Thread: pthread locks
hello everyone, there can me mutexes? i've got program threads increasing counter , when counter reach value signal sent threads waiting other job.
void *count(){
(i=0 ; i<count_per_thread ; i++) {
pthread_mutex_lock(&mtx)
count++;
if (count == threshold)
pthread_cond_signal(&cond);
....
pthread_mutex_unlock(&mtx);
}
}
void *suspend(){
pthread_mutex_lock(&mtx)
while (count < threshold) {
pthread_cond_wait(&cond, &mtx);
...
pthread_mutex_unlock(&mtx);
}
in case if thread in suspend function lock mtx how other threads in count function increase counter? :/
thank u
pthread_cond_wait atomically unlocks mutex , goes sleep until signaled. mutex free locked thread.
when wakes locks mutex again
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk pthread locks
Ubuntu
Comments
Post a Comment