Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

[Autumn] Multithreaded access to EventDispatcher #74

Open
Velaskes11 opened this issue Jan 31, 2018 · 1 comment
Open

[Autumn] Multithreaded access to EventDispatcher #74

Velaskes11 opened this issue Jan 31, 2018 · 1 comment
Assignees
Milestone

Comments

@Velaskes11
Copy link

Velaskes11 commented Jan 31, 2018

I use EventDispatcher.postEvent in several threads.
Some times I get exception:

Fatal Exception: com.badlogic.gdx.utils.j
#iterator() cannot be used nested.

com.badlogic.gdx.utils.ObjectSet$ObjectSetIterator.hasNext (SourceFile:533)
com.github.czyzby.autumn.processor.event.EventDispatcher.invokeEventListeners (SourceFile:132)
com.github.czyzby.autumn.processor.event.EventDispatcher.postEvent (SourceFile:121)
com.a.b.c$$Lambda$0.run (Unknown Source:1099)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
java.lang.Thread.run (Thread.java:761)

It is correct to use it from multiple threads?
It seems that need synchronization in method invokeEventListeners or something like this.

@czyzby
Copy link
Owner

czyzby commented Jan 31, 2018

Well, if the event listeners are thread-safe/stateless and they collection never changes, this should not cause any issues - iteration over effectively immutable list of listeners should not cause any problems. The exception is thrown because LibGDX ObjectSet reuses its iterator and this causes issues when used from within multiple threads. I'll look into this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants