For a certain project,I have to use the static mutex initializer in pthread.However my library is supposed to be portable on Windows as well.
pthread_mutex_t csapi_mutex = PTHREAD_MUTEX_INITIALIZER;
Is there a corrosponding static initializer on windows.?
Thanks.
I came up with this port of pthread-compatible mutex operations:
Basically, you want the initialization to happen atomically when the lock is used the first time. If two threads enter the if-body, then only one succeeds in initializing the lock. Note that there is no need to CloseHandle() for the static lock’s lifetime.