Re: Posix mutex working in Linux but not Solaris
- From: Frank Cusack <fcusack@xxxxxxxxxxx>
- Date: Thu, 07 Feb 2008 18:47:20 -0800
On Thu, 7 Feb 2008 18:28:26 -0800 (PST) Cheng <cheng.stillsea@xxxxxxxxx> wrote:
Hi I created my_mutex of posixMutex type (basically pthread_mutex_t
type) accessed by 2 threads, which execute the same section of code:
void run() {
my_mutex.lock();
/*calculates sth here*/
my_mutex.unlock();
}
It runs perfectly on Linux with arbitrary number of threads, but on
Solaris (ver. 8) it prints the following and exits without a core dump
when only 2 threads are created.
ERROR -- call to pthread_mutex_lock() -- called on locked mutex
Has anybody seen anything like this before? Thanks.
Yes, lots. You have a buggy program.
***** The lock and unlock functions are borrowed from online, which
take care of recursive locking situations:
you don't have a recursive locking problem, you have a contended mutex.
void
posixMutex::lock()
{
if (m_dontLock)
return;
threadID thisthreadID = getThisThreadID();
if (isProcessLocked() && lockedBy() == thisthreadID)
{
m_state.m_lockCount++;
return;
}
here, the mutex is "locked" recursively if the thread requesting a
new lock is the thread that already holds the lock. fine. but
if the thread requesting the lock is DIFFERENT than the thread that
holds the lock, we continue on ...
int retVal = pthread_mutex_lock(&m_mutex);
to here, and this will fail. which is the correct action.
the reason it works on Linux is that the mutex is never contended,
due to thread scheduling differences.
BTW, the class seems pointless since pthreads provides recursive
mutexes natively. also, the class is buggy since it doesn't test for
overflow of m_state.m_lockCount (i assume m_state is a struct and
m_lockCount is an integral type and not an object which will throw an
exception on overflow).
-frank
.
- Follow-Ups:
- Re: Posix mutex working in Linux but not Solaris
- From: Cheng
- Re: Posix mutex working in Linux but not Solaris
- References:
- Posix mutex working in Linux but not Solaris
- From: Cheng
- Posix mutex working in Linux but not Solaris
- Prev by Date: Re: Posix mutex working in Linux but not Solaris
- Next by Date: Re: how to undo lpshut
- Previous by thread: Re: Posix mutex working in Linux but not Solaris
- Next by thread: Re: Posix mutex working in Linux but not Solaris
- Index(es):
Relevant Pages
|
|