Rob Landley wrote:
Could you post your simple test program? I tried to come up with one
(attached), built it with:
i686-gcc thread-hello2.c -lpthread --static
And it worked exactly the same way on gcc and on uClibc (with svn 23784).
My uClibc .config is also attached.
My program attached.
I did not do fork() in my code. I suspect there is a difference
between if you do fork() in your code vs when you do
fork() in uclibc library.
In the function main(), it calls the uclibc library daemon(),
then the thread will hang. But if I call my_daemon(), which
is the exact replica of uclibc daemon() in source, then it
will not hang.
Regards.
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <features.h>
#include <fcntl.h>
#include <paths.h>
#include <unistd.h>
#define NUM_THREADS 3
int my_daemon( int nochdir, int noclose )
{
int fd;
switch (fork()) {
case -1:
return(-1);
case 0:
break;
default:
_exit(0);
}
if (setsid() == -1)
return(-1);
/* Make certain we are not a session leader, or else we
* might reacquire a controlling terminal */
if (fork())
_exit(0);
if (!nochdir)
chdir("/");
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > 2)
close(fd);
}
return(0);
}
void *BusyWork(void *null)
{
int i;
double result=0.0;
for (i=0; i<1000000; i++)
{
result = result + (double)random();
}
printf("result = %e\n",result);
pthread_exit((void *) 0);
}
int main (int argc, char *argv[])
{
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t;
void *status;
daemon(1,1);
/* Initialize and set thread detached attribute */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for(t=0; t<NUM_THREADS; t++)
{
printf("Creating thread %d\n", t);
rc = pthread_create(&thread[t], &attr, BusyWork, NULL);
if (rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Free attribute and wait for the other threads */
pthread_attr_destroy(&attr);
for(t=0; t<NUM_THREADS; t++)
{
rc = pthread_join(thread[t], &status);
if (rc)
{
printf("ERROR; return code from pthread_join() is %d\n", rc);
exit(-1);
}
printf("Completed join with thread %d status= %ld\n",t, (long)status);
}
pthread_exit(NULL);
}
_______________________________________________
uClibc mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/uclibc