Threads and Events

BlitzMax Forums/BlitzMax Programming/Threads and Events

BORNtobeNAMELESS(Posted 2009) [#1]
Is it possible to Post Events from a thread to the main programs EventQueue? Are the eventQueue seperated, or can i just Post the event? Is it secure to Emit my events, or will it crash if two threads try to emit events at the same time?


ImaginaryHuman(Posted 2009) [#2]
Hey, new territory. We'd need to know if the event system is `safe` using mutexes or whatever. Otherwise you can use your own mutex - ie set up a `postbox manager` which only allows one thread to post/read events at a time - or set up an event thread which handles all events and virtualizes it to all other threads, sending/getting messages to/from them in a safe way.


BORNtobeNAMELESS(Posted 2009) [#3]
An other question would be if WaitEvent would return from WaitSystem if a thread posts an event to the event loop, or if it just continues waiting.

Edit: The problem with the current Event-System is that if i Emit an event the EmitEventHooks get called from inside the thread that emits the event, which makes it neccessary for the Hook to be thread-safe. A solution might be to add a Mutex that protecs TEvent.Emit, but that can't stop the Hook from manipulating data that something outside an Event is accessing at the same time...