Results 1 to 3 of 3
Hello All, I was studying pthreads today. If multiple threads operate on a single shared resource, we can lock it using pthread_mutex_lock. Uptill that it is fine, but why again ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-02-2011 #1
- Join Date
- Dec 2010
[SOLVED] pthread : pthread_cond_wait
I was studying pthreads today.
If multiple threads operate on a single shared resource, we can lock it using pthread_mutex_lock. Uptill that it is fine, but why again pthread_cond_wait?
int shared=0; // global
// Thread 1
When thread1 invokes the mutex lock, no other threads can access it in parallel. So why again and what for we use, pthread_cond_wait( ). Someone kindly help me with a good code example.
- 03-03-2011 #2
- Join Date
- Jun 2010
pthread_cond_wait is used in cases where one thread needs to wait for another thread to complete a job in order to proceed. In such cases you don't want to be sleeping and polling a state, you simply want to be notified when things are done and you can proceed.
This function also with pthread_cond_timedwait and be used to implement a message queue for message passing between threads. In an event driven software design architecture.
- 03-03-2011 #3