From: Guillaume Morin <guillaume@morinfr.org>
To: linux-kernel@vger.kernel.org
Cc: gmorin1@bloomberg.net
Subject: [NPTL] situation where pthread_exit() makes the whole process exit
Date: Thu, 4 Nov 2004 18:29:32 +0100 [thread overview]
Message-ID: <1099589372.418a66fc54599@mail.morinfr.org> (raw)
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
call pthread_exit(). The remaining thread should execute and then only
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.
PS: please keep all the CCs. Thanks in advance.
--
Guillaume Morin <guillaume@morinfr.org>
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
reply other threads:[~2004-11-04 17:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1099589372.418a66fc54599@mail.morinfr.org \
--to=guillaume@morinfr.org \
--cc=gmorin1@bloomberg.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®