Synchronizing multiple threads using TEvent
The synchronization details we discussed so far were related to a data flow that is generated in the background thread context and has to be used in another thread. The other thread can be the main thread or another background thread. In this recipe, you'll use a simple synchronization mechanism called event that can be useful when you have to notify a new state, not necessarily new data. Obviously, the new state could also mean there is new data to handle. In such cases, the state change alerts you about new data being available.
Getting ready
The recipe scenario is simple: you have a lot of running threads that are doing something for you. You want to know when all of them are terminated. In this case, you can use a TEvent
object (this is a tiny wrapper around an OS Event
object).
How to do it…
This recipe is a bit articulated, so we'll not discuss steps to recreate it. Please open the recipe project code named ThreadsTermination.dproj
; let's comment...