Skip to main content

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

Popular posts from this blog

Adobe Acrobat Pro , Terminal Server Use

Thread: transmission-daemon isn't playing nice: "409: Conflict"

Thread: gpg: Conflicting Commands