Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Sep 2004 09:05:48 +0100
From:      Chris Stenton <jacs@gnome.co.uk>
To:        freebsd-current@freebsd.org
Cc:        threads@freebsd.org
Subject:   daemon threads bug with libpthread
Message-ID:  <1095840348.23443.14.camel@hawk.gnome.co.uk>

next in thread | raw e-mail | index | archive | help
If you create a thread before calling daemon then the next thread you
create after the daemon call will cause the following error from the
libpthread library.

Fatal error 'mutex is on list' at line 516 in file
/usr/src/lib/libpthread/thread/thr_mutex.c (errno = 0)

This error does not occur if you link with -lc_r, linking with -lthr
causes a core dump. -lthr does not look very stable.

Here is some test code. I am running FreeBSD 5.3-beta

Please reply directly as I am not on the mailing list

Thanks


Chris
 				
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>


void *slave (void *args);
void *slave2 (void *args);

typedef struct {
	int data;
	pthread_mutex_t *mut;
} simple;


	simple  status;

int main ()
{
	pthread_t sla, sla2;

	
	pthread_create (&sla, NULL, slave, &status);
	pthread_join(sla, NULL);

	daemon(0,1);
	
	pthread_create (&sla2, NULL, slave2, &status);

	for(;;){
		
	}

	return 0;
}


void *slave (void *arg)
{
	simple  *status;

	status  = (simple  *)arg;
	
	pthread_mutex_lock (status->mut);
	status->data++;
	usleep(500000);
	printf("******slave me me me %d  *********** \n",status->data );
	pthread_mutex_unlock (status->mut);
	
	return (NULL);
}

void *slave2 (void *arg)
{
	simple  *status;

	status  = (simple  *)arg;

	for(;	/* ever */ ;) {
		
	
		pthread_mutex_lock (status->mut);
		status->data++;
		usleep(500000);
		printf("******slave2 me me me %d  \n",status->data );
		pthread_mutex_unlock (status->mut);
	}

		return (NULL);
}





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1095840348.23443.14.camel>