#Header
#include "co/thread.h"
The API is in the co namespace.
#Thread ID
uint32 co::thread_id();
- Returns the current thread id.
#Synchronization Event
std::condition_variableallows spurious wakeups,notify_onedoes not guarantee waking only one waiting thread, andwaitrequires a lock, making it inconvenient to use. coost implementsco::sync_eventto replace it.
struct sync_event {
sync_event(bool manual_reset, bool signaled);
sync_event() : sync_event(false, false) {}
~sync_event();
sync_event(sync_event&& e) noexcept : _p(e._p) { e._p = 0; }
sync_event(const sync_event&) = delete;
void operator=(const sync_event&) = delete;
void operator=(sync_event&&) = delete;
void notify_one();
void notify_all();
void reset();
void wait();
bool wait(uint32 ms);
void* _p;
};
notify_onewakes only one waiting thread.notify_allwakes all waiting threads.waitblocks until it is woken up or times out; it does not suffer from spurious wakeups.- It supports auto-reset and manual-reset modes. In auto-reset mode,
waitresets the signal to theunsignaledstate when it returns. resetis used in manual-reset mode to reset the signal to theunsignaledstate.