I'm aware of undefined behavior on calling pthread_cond_destroy() when there is 1+ thread waiting on a condition variable and I'm looking for a workaround to send wake signal to all threads waiting on a condition variable before calling pthread_cond_destroy().
My CV class destructor calls pthread_cond_destroy() if condition variable is valid. Therefore, I thought of:
-
Broadcasting before calling pthread_cond_destroy() but that would wake just 1 thread. I want destructor to succeed and that no thread should be able to wait on the cv object (No dereferencing on destructed object).
-
Is signal counting (along with workaround #1) a way to fix this issue? If so, how do I ensure that all waiting threads have been scheduled (woken up) before ~CV() succeeds?
-
Do I overcome this issue if I use C++ 11 thread/condition variable?
Aucun commentaire:
Enregistrer un commentaire