daemon threads bug with libpthread
Chris Stenton
jacs at gnome.co.uk
Wed Sep 22 01:05:54 PDT 2004
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);
}
More information about the freebsd-current
mailing list