A simple synchronization tool that allows one or more thread to wait until a specific condition is reached.
A CYICountDownLatch instance is created with a Count. The count can be decreased (no lower than 0) by a call to CountDown(). When the count reaches 0, the Finished signal is triggered. Calls to Wait() will block until the Count reaches 0.
All functions in this class, with the exception of the destructor, are thread-safe.
- Note
- CYICountDownLatch instances cannot be 'reset' once their Count reaches zero.
-
If a CYICountDownLatch is created with a Count of 0, the Finished signal will never be triggered. Any call to the Wait() functions will return immediately.
- Warning
- When used between multiple threads (and really this is the only reason why someone would use this class), instances of this object cannot be destroyed safely as it's impossible to know if there's still threads waiting on the latch. For that reason, it is recommended that instances of CYICountDownLatch always be stored and used through an std::shared_ptr.
- See also
- std::shared_ptr<YI_PTR_TYPE>