e***@nospam.com
2005-01-31 22:41:44 UTC
Hi,
Consider following pseudo-code:
void foo() {
pthread_mutex_lock(&mux);
while (in_use == 0) {
pthread_cond_wait(&cond, &mux);
}
in_use=0;
pthread_mutex_unlock(&mux);
pthread_cond_signal(&cond);
}
I've read that pthread_cond_signal(&cond) should actually be inside the
locked code segment (critical section) and not outside as shown in the
example above. Any comments on why one of the correct solutions is the
way to go? Both work for me but I'm quite confident that one is wrong.
Regards,
Roberto Nibali, ratz
Consider following pseudo-code:
void foo() {
pthread_mutex_lock(&mux);
while (in_use == 0) {
pthread_cond_wait(&cond, &mux);
}
in_use=0;
pthread_mutex_unlock(&mux);
pthread_cond_signal(&cond);
}
I've read that pthread_cond_signal(&cond) should actually be inside the
locked code segment (critical section) and not outside as shown in the
example above. Any comments on why one of the correct solutions is the
way to go? Both work for me but I'm quite confident that one is wrong.
Regards,
Roberto Nibali, ratz
--
echo
'[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
echo
'[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc