I have multiple threads accessing shared data. I want to put a lock on that code so that the clients access it one at a time. How should i do this?
This is a discussion on Pthread Mutex lock help within the C Programming forums, part of the General Programming Boards category; I have multiple threads accessing shared data. I want to put a lock on that code so that the clients ...
I have multiple threads accessing shared data. I want to put a lock on that code so that the clients access it one at a time. How should i do this?
There're many resources out there.Code:pthread_mutex_t lock; int shared_data; pthread_mutex_init(&lock,NULL); .... pthread_mutex_lock(&lock); // use shared_data pthread_mutex_unlock(&lock);
Multithreaded Programming (POSIX pthreads Tutorial)