daemon threads bug with libpthread

From: Chris Stenton <jacs_at_gnome.co.uk>
Date: Wed, 22 Sep 2004 09:05:48 +0100
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);
}
Received on Wed Sep 22 2004 - 06:05:54 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:13 UTC