Forum Stats

  • 3,851,949 Users
  • 2,264,053 Discussions
  • 7,904,914 Comments

Discussions

pthread_mutex_lock hangs on SunOS 5.6

807578
807578 Member Posts: 13,959 Green Ribbon
I have a simple threaded program (which is duplicating a portion of a much larger program I have) that works on my Sun 5.5.1 system, but hangs on my Sun 5.6 system...

#include <pthread.h>

void runThread(void);
void set(pthread_mutex_t& rMutex);

pthread_mutex_t* pMutex;

int main(void)
{
pthread_mutex_t mutex;
pthread_t thread;

set(mutex);
pthread_create(&thread, NULL, (void*(*)(void*))runThread, NULL);
pthread_join(thread, NULL);
return 1;
}

void set(pthread_mutex_t& rMutex)
{
pMutex = &rMutex;
}

void runThread(void)
{
pthread_mutex_lock(pMutex); // Program hangs here waiting for a
// lock that it never obtains
pthread_mutex_unlock(pMutex);
}

The program will hang on my Sun 5.6 box in the runThread function while trying to invoke the pthread_mutex_lock function. I'm sure some of you may wonder what that set function is all about, but please just accept that I need to have it.

Here is some additional information about my two Sun boxes...

Works on this box
Release: 5.5.1
Kernel architecture: sun4u
Application architecture: sparc
Hardware provider: Sun_Microsystems
Kernel version: SunOS 5.5.1 Generic 103640-32 November 1999
Patched through 108658-02

Doesn't work on this box
Release: 5.6
Kernel architecture: sun4u
Application architecture: sparc
Hardware provider: Sun_Microsystems
Kernel version: SunOS 5.6 Generic 105181-20 January 2000
Patched through 109339-01

Both boxes are running this compiler...

CC: WorkShop Compilers 4.2 16 Jun 1998 C++ 4.2 patch 104631-07
tdb_link: WorkShop Compilers 4.2 16 Jun 1998 C++ 4.2 patch 104631-07
CC: WorkShop Compilers 4.2 16 Jun 1998 C++ 4.2 patch 104631-07
/opt/SUNWspro/bin/../SC4.2/bin/c++filt: WorkShop Compilers 4.2 16 Jun 1998
ild: WorkShop Compilers 4.2 15 Oct 1996 ILD 2.0

Thanks!

Comments

  • 807578
    807578 Member Posts: 13,959 Green Ribbon
    I tried your code on solaris 5.6 and could easily see it
    hanging in pthread_mutex_lock.
    (dbx) run
    Running: a.out
    (process id 483)
    ^Cdbx: warning: Interrupt ignored but forwarded to child.
    [email protected] ([email protected]) signal INT (Interrupt) in ___lwp_mutex_lock at 0xef6f96fc
    0xef6f96fc: ___lwp_mutex_lock+0x0008: ta 0x8
    Current function is runThread
    22 void runThread(void) { pthread_mutex_lock(pMutex);
    (dbx)

    But, when i tried to initialise the mutex using

    pthread_mutex_init(&mutex, 0);

    just before doing a set() in the main(),

    the problem is no longer seen.

    (dbx) run
    Running: a.out
    (process id 470)

    execution completed, exit code is 1
    (dbx)

    Hope this helps!

    -Prasad
This discussion has been closed.