Linux/POSIX equivalent for Win32’s CreateEvent, SetEvent, WaitForSingleObject

The POSIX equivalent for what you described is POSIX condition variables. Note that condition variable must always be used in pair with a POSIX mutex, but quite frequently several condition variables use the same mutex, so if you aren’t going to use the mutex exclusively for the condition variable, you shouldn’t place it in the class. The mappings by meaning in your case between Win32 and POSIX API should be:

CreateEvent -> pthread_cond_init

CloseHandle -> pthread_cond_destroy

WaitForSingleObject -> pthread_cond_wait or pthread_cond_timedwait

SetEvent -> pthread_cond_signal or pthread_cond_broadcast

Fortunately, there is a lot of documentation regarding this, though I recommend the fundamental Programming POSIX Threads.

Leave a Comment