mutex locking [Archive] - C Board

PDA

View Full Version : mutex locking


quagsire
11-27-2002, 04:53 AM
If I use mutex blocking like this

pthread_mutex_lock (&send_mutex);
try
{
Send( pBuffer, ulMsgSize );
}
catch(...)
{
pthread_mutex_unlock (&send_mutex);
throw;
}
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?

Hammer
11-27-2002, 05:44 PM
Based on what is says here (http://www.rt.com/man/pthread_mutex_lock.3.html), 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.

biosninja
11-28-2002, 09:08 AM
mutex blocking

what's that? never heard of it

Jaguar
11-29-2002, 10:47 AM
See mutex (http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=mutex)