Thread: Pthread Mutex lock help

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Pthread Mutex lock help

    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?

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    pthread_mutex_t lock;
    int shared_data;
    
    pthread_mutex_init(&lock,NULL);
    ....
    pthread_mutex_lock(&lock);
    // use shared_data
    pthread_mutex_unlock(&lock);
    There're many resources out there.
    Multithreaded Programming (POSIX pthreads Tutorial)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help in Pthread and Mutex program
    By besty in forum C Programming
    Replies: 1
    Last Post: 11-12-2010, 04:04 PM
  2. Mutex, Cond and Thread questions (pthread, linux)
    By thebearot in forum C Programming
    Replies: 14
    Last Post: 04-23-2010, 12:10 PM
  3. Mutex lock question
    By cjjoy1980 in forum Linux Programming
    Replies: 3
    Last Post: 07-17-2009, 10:05 AM
  4. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 02:38 AM
  5. pthread mutex problemos
    By cnchybrid in forum C Programming
    Replies: 0
    Last Post: 04-05-2007, 11:20 AM

Tags for this Thread