Consider the following source code, which is fully POSIX compliant:
#include
#include
#include
#include
You can defend your code against this problem. One easy way is to have one thread whose sole purpose is to watch the system clock. You keep a global linked list of condition variables, and if the clock watcher thread sees a system clock jump, it broadcasts every condition variable on the list. Then, you simply wrap pthread_cond_init
and pthread_cond_destroy
with code that adds/removes the condition variable to/from the global linked list. Protect the linked list with a mutex.