I have been working with pthread_cond_t and associated functions and I read that usually a mutex is used in conjunction with the condition when calling pthread_cond_wait or pthread_cond_signal/broadcast. The online texts only mention that the mutex is used for 'predictable behaviour'. Does this mean that there's no need to use a mutex with a condition? Can someone explai what is going on? Thanks.

Well, it seems that a call to pthread_cond_wait unlocks the mutex passed into it. Then when it returns (When the condition is signaled) it locks the corresponding mutex. so u have to unlock it manually. Well, this makes me to think that the need for the mutex is to make the operations on the condition variable thread safe.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.