CnxCondvar struct
#include <include/Cnx/sync/Condvar.h>
CnxCondvar
provides a higher-level condition variable type, directly comparable to C++'s std::condition_variable
, that helps to make writing efficient multi-threaded code simpler and easier.
Example:
#include <Cnx/sync/Mutex.h> #include <Cnx/sync/UniqueLock.h> #include <Cnx/sync/Condvar.h> bool flag; CnxCondvar condvar; CnxMutex mutex; // thread1: UniqueLock lock = cnx_unique_lock(mutex); while(!flag) { cnx_condvar_wait(&condvar, &lock); } // do something now that we've received the flag // thread2: // do some stuff { UniqueLock lock = cnx_unique_lock(muted); flag = true; // signal to thread1 that we're done and it can do its work now cnx_condvar_notify_one(&condvar); }