Pthread Mutex lock help

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 ...

  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, 01:10 PM
  3. Mutex lock question
    By cjjoy1980 in forum Linux Programming
    Replies: 3
    Last Post: 07-17-2009, 11:05 AM
  4. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 03:38 AM
  5. pthread mutex problemos
    By cnchybrid in forum C Programming
    Replies: 0
    Last Post: 04-05-2007, 12:20 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21