BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
Joiner implements join() on a thread that can be called multiple times from different threads. The point is that the Poco::Thread::join() MUST NOT be called twice (unless its timeout exceeds). More...
#include <Joiner.h>
Public Member Functions | |
Joiner (Poco::Thread &thread) | |
void | join (const Poco::Timespan &timeout=-1) |
Join the underlying thread. The timeout controls whether we are waiting indefinitely (when negative) or we can be interrupted by timeout. More... | |
bool | tryJoin (const Poco::Timespan &timeout=-1) |
Join the underlying thread. The timeout controls whether we are waiting indefinitely (when negative) or we can be interrupted by timeout. More... | |
Protected Member Functions | |
void | joinFromMany (long ms) |
Implement locking to allow exactly 1 thread to call the join(). The lock respects the given timeout. | |
void | doJoin (long ms) |
Call the actual join based on the timeout. | |
Joiner implements join() on a thread that can be called multiple times from different threads. The point is that the Poco::Thread::join() MUST NOT be called twice (unless its timeout exceeds).
The Joiner creates a queue of joining threads via FastMutex. All the threads are waiting on the mutex except one (in FIFO order) that performs the actual join(). If this single join succeeds, all other threads would return successfully. If the single one join does not succeeds (due to timeout), the next thread in the queue performs the actual join(), etc.
void Joiner::join | ( | const Poco::Timespan & | timeout = -1 | ) |
Join the underlying thread. The timeout controls whether we are waiting indefinitely (when negative) or we can be interrupted by timeout.
Poco::TimeoutException | when the timeout exceeds |
bool Joiner::tryJoin | ( | const Poco::Timespan & | timeout = -1 | ) |
Join the underlying thread. The timeout controls whether we are waiting indefinitely (when negative) or we can be interrupted by timeout.