OpenSolaris

Printable Version Enter a New Search
Bug ID 6738798
Synopsis pthread_mutex_timedlock can block forever when using priority inherit mutexes
State 10-Fix Delivered (Fix available in build)
Category:Subcategory library:libc
Keywords
Responsible Engineer Roger Faulkner
Reported Against
Duplicate Of
Introduced In solaris_8
Commit to Fix snv_98
Fixed In snv_98
Release Fixed solaris_nevada(snv_98)
Related Bugs
Submit Date 19-August-2008
Last Update Date 10-September-2008
Description
This was reported by David Bartley < xxxxx@xxxxx.ca>
on opensolaris- xxxxx@xxxxx.org :

pthread_mutex_timedlock does not return when passed a valid abstime if mutex
is a priority inherit mutex. The attached test case demonstrates the bug.

Ths (slightly revised) test case is:

/* compile as 'gcc pthread_mutex_timedlock-PI.c' */

#include <pthread.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <errno.h>

/* ARGSUSED */
static void
intr(int sig)
{
}

int
main()
{
        pthread_mutexattr_t a;
        pthread_mutex_t m;
        struct timespec t;
        int err;

        assert(sigset(SIGALRM, intr) == SIG_DFL);

        assert(pthread_mutexattr_init(&a) == 0);

#ifndef NO_PI
        assert(pthread_mutexattr_setprotocol(&a, PTHREAD_PRIO_INHERIT) == 0);
#endif

        assert(pthread_mutex_init(&m, &a) == 0);

        assert(pthread_mutex_lock(&m) == 0);

        assert(alarm(2) == 0);

        assert(clock_gettime(CLOCK_REALTIME, &t) == 0);
        t.tv_sec += 5;

        /* this should block for 5 seconds */
        err = pthread_mutex_timedlock(&m, &t);
        assert(err == ETIMEDOUT);

        return (0);
}
Work Around
Don't try to acquire a mutex that you already own.
Comments
N/A