mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [NPTL] situation where pthread_exit() makes the whole process exit
@ 2004-11-04 17:29 Guillaume Morin
  0 siblings, 0 replies; only message in thread
From: Guillaume Morin @ 2004-11-04 17:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: gmorin1

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/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-04 17:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-04 17:29 [NPTL] situation where pthread_exit() makes the whole process exit Guillaume Morin

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®