This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug nptl/530] New: pthread_exit() makes the whole process exit if remaining threads were just created
- From: "gmorin1 at bloomberg dot net" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 9 Nov 2004 17:34:16 -0000
- Subject: [Bug nptl/530] New: pthread_exit() makes the whole process exit if remaining threads were just created
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
Hi,
On Linux 2.6.9, I am having a problem with pthread_exit().
My test program creates a thread from the main thread, detaches it, then
calls pthread_exit(). The remaining thread should execute and only then
the process should exit. It is not what's happening right now. The
program returns right away.
To figure out easily where we are, the spawned thread prints some stuff,
sleeps for 5 seconds and then prints something else.
If you launch that program, it will not print anything and return
right away. If you pass a parameter to the program, the main thread
will call sched_yield() before calling pthread_exit(). In this case, it
will work:
gmorin@linux:~> time ./foo
real 0m0.001s
user 0m0.000s
sys 0m0.001s
gmorin@linux:~> time ./foo yield
In f, sleeping 5 secs
Reached
real 0m5.003s
user 0m0.000s
sys 0m0.002s
gmorin@linux:~>
So it looks like the problem only appears if the spawned thread was not
scheduled.
FYI, Linuxthreads works well:
gmorin@linux:~> LD_ASSUME_KERNEL=2.4.1 ./foo
In f, sleeping 5 secs
Reached
Here is the source of the program:
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
void * f(void * arg) {
puts("In f, sleeping 5 secs");
fflush(stdout);
sleep(5);
puts("Reached");
return NULL;
}
int main(int argc,char *argv[]) {
pthread_t t;
if (pthread_create(&t, NULL, f, NULL)) {
printf("error %s\n", strerror(errno));
return 1;
}
if (pthread_detach(t)) {
printf("error %s\n", strerror(errno));
return 1;
}
if (argc > 1)
sched_yield();
pthread_exit(0);
// not reached
return 2;
}
HTH. Guillaume.
--
Summary: pthread_exit() makes the whole process exit if remaining
threads were just created
Product: glibc
Version: 2.3.3
Status: NEW
Severity: normal
Priority: P2
Component: nptl
AssignedTo: drepper at redhat dot com
ReportedBy: gmorin1 at bloomberg dot net
CC: glibc-bugs at sources dot redhat dot com
http://sources.redhat.com/bugzilla/show_bug.cgi?id=530
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.