Hi, I'm asking for further assistance for yet another problem I
encounter with my project, this time concerning multithreads.
In order to explain my problem, I'll write a short example:
main:
pthread_mutex_lock(&mut);
flag = 0;
pthread_cond_broadcast(&cond);
printf("after signal: flag=%d\n", flag);
pthread_mutex_unlock(&mut);
.......
thread:
pthread_mutex_lock(&mut);
while (flag)
{
pthread_cond_wait(&cond, &mut);
printf("after wait: flag=%d\n", flag);
}
pthread_mutex_unlock(&mut);
......
Now, after signal I indeed see that flag is 0.
Flag is assigned 1 in 2 other places in main, in both cases surrounded
by lock and unlock of the same mutex.
Wha happens, that after wait, flag is still 1 and the thread is stuck in
the loop, and I feel helpless.
This code is based on my understandings from the documentation about
threads and also follows the examples I saw.
What should I do so that after wait flag will be 0 as I expect it to be
according to this example?
If this is not directly in this code piece, maybe somebody can give me
some clues what may cause flag to remain 1 after wait to see if anything
of this exists in the whole program.
Thanks, Rafi.