I write simple pthread example using condition to sync two threads. in some situation signal called before wait and wait-thread lock forever.
Is there way to detect signal before wait ?
void *Thread1(void *args){
sleep(1);
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
pthread_mutex_unlock(&mutex);
}
void *Thread2(void *args){
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}