I have two events that are being fired and handled by two event handlers.
In EventHandler2
a boost::thread
is started.
In EventHandler2 the application is waiting for this thread to finish by calling join()
on it.
This has workled well on fast computers, because the event that started the thread was always fired first, before the other event that caused the application to ait for the join()
.
However, on old machines, the events are fired in different order (because there is some heavy computing to be done before EventHandler2
is called).
So EventHandler1
is called first and does not wait, since the join()
immediately returns (thread has not been started yet, becuase the 2nd event was not fired).
whats the best I can do here? Do I need to lock a mutex and then wait for it before I call the join()
. This way I make sure that the thread is started before a join()
is called on it.
Whats the best pattern to use in this case?
Thank you!