Date: Tue, 20 Oct 98 13:05:03 -0500 From: "Richard Seaman, Jr." <lists@tar.com> To: "Jason Evans" <jasone@canonware.com> Cc: "current@freebsd.org" <current@FreeBSD.ORG> Subject: Re: Another Serious libc_r problem Message-ID: <199810201805.NAA11025@ns.tar.com>
next in thread | raw e-mail | index | archive | help
On Mon, 19 Oct 1998 18:03:22 -0700 (PDT), Jason Evans wrote:
>Hmm, your test case is very similar to some code that was causing deadlock
>for me. However, I boiled it down to the following code as being the
>actual bug. We may be seeing the same thing (but maybe not; I haven't had
>time to dig into this all the way).
>
>Jason
I think the problem in your code is that you expect to be able to recursively
lock a mutex in the same thread, using the default mutex type. I don't
think this is a bug, since the "default" mutex type is implementation
defined, if I'm not mistaken.
Try the following adjustments to your code:
/* -*-mode:c-*- */
#ifndef _REENTRANT
# define _REENTRANT
#endif
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int
pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
int
main()
{
pthread_mutex_t mutex;
pthread_mutexattr_t attr;
int error;
pthread_mutexattr_init (&attr);
pthread_mutexattr_setkind_np (&attr, MUTEX_TYPE_COUNTING_FAST);
error = pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy (&attr);
if (error)
{
fprintf(stderr, "Error in pthread_mutex_init(): %s\n", strerror(error));
exit(1);
}
fprintf(stderr, "About to lock mutex first time.\n");
error = pthread_mutex_lock(&mutex);
if (error)
{
fprintf(stderr, "Error in pthread_mutex_lock(): %s\n", strerror(error));
exit(1);
}
fprintf(stderr, "About to lock mutex second time; expect deadlock.\n");
error = pthread_mutex_lock(&mutex);
if (error)
{
fprintf(stderr, "Error in pthread_mutex_lock(): %s\n", strerror(error));
exit(1);
}
fprintf(stderr, "Wow, no deadlock.\n");
error = pthread_mutex_destroy(&mutex);
if (error)
{
fprintf(stderr, "Error in pthread_mutex_destroy(): %s\n", strerror(error));
exit(1);
}
return 0;
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810201805.NAA11025>
