Thread: mutex locking

  1. #1
    Registered User quagsire's Avatar
    Join Date
    Jun 2002

    mutex locking

    If I use mutex blocking like this
    pthread_mutex_lock (&send_mutex);
      Send( pBuffer, ulMsgSize );
     pthread_mutex_unlock (&send_mutex);
    pthread_mutex_unlock (&send_mutex);
    will the mutex be unblocked if the thread terminates inside the Send function?

    I know with semaphores you can use the SEM_UNDO flag for that purpose, but how can you do it with mutexes?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Based on what is says here, I'm going to guess the lock isn't released until you explicitly do so.
    An equal number of pthread_mutex_unlock operations must be performed before the mutex returns to the unlocked state.
    Why not write a small program and test your theories.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    South Africa
    mutex blocking
    what's that? never heard of it
    The knack of flying is learning to throw yourself at the ground and miss.

  4. #4
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    See mutex
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. mutex problem
    By radeberger in forum C++ Programming
    Replies: 16
    Last Post: 03-20-2009, 04:24 PM
  3. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  4. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  5. Mutex in C
    By jgs in forum Windows Programming
    Replies: 4
    Last Post: 05-21-2005, 07:11 AM