Open yellowsink opened 4 months ago
If it is simply the case that threads may only wait for events created on their own thread, I think this should be documented more clearly, but that also would significantly increase the difficulty of syncing threads so I'm hoping this is just a bug that can be fixed!
The problem here is that each event ID is only valid for the event driver instance that created it. So in order to wait from another thread, you have to pass the main thread's eventDriver
as cast(shared)eventDriver
to the other thread and then call the shared
overload of wait
there. I'll add some documentation for this.
ah! I was aware of shared trigger but not shared wait. doesn't this mean that you'd need to use a shared processevents too, though? I suppose the only way to do what I want is to make sure it's constructed on the second thread... should be doable
Oh wait, you are right, I misremembered that. There is indeed no shared
wait! So it actually needs to be turned around to work and the waiting thread needs to create the event. I'm not quite sure whether this is something that can be improved without introducing additional locking within the driver, which would certainly impair performance.
I can probably work around this in my wrapper struct I have - I can keep a map of thread ids to (eventid, shared(eventdriver)) and that should work, but I suppose if making this work would result in a general slowdown for usage of events in eventcore its most likely better placed as a hit taken in user code than there.
I can probably work around this in my wrapper struct I have
I've got this working - so I suppose it's really just a docs change that's needed to clarify the requirement to wait on the same thread as create
When attempting to wait for an event created on the main thread from a second thread (as far as I can tell from the documentation, that is allowed), the wait() call (not even processevents!) causes an assertion failure in taggedunion.
I've attached a minimal reproduction, but for reference, I encountered this within a more complex project with this demo code: https://github.com/yellowsink/rockhopper/blob/ed05a03/source/app.d
Minimal reproduction code:
library versions:
exception message (DMD, LDC gives a more compact stack trace):