Date: Mon, 31 Jan 2005 23:29:11 +0100 From: Tomas Ulin <tomas@mysql.com> To: freebsd-threads@freebsd.org Subject: wrong exit code with linux threads Message-ID: <41FEB137.7040402@mysql.com>
next in thread | raw e-mail | index | archive | help
Hi, the program below (tmp.c) gives strange output regarding the child exit status when using linux threads on freebsd 4.7. With lib pthread- correct: Exit value 123 Exit value 123 With llthread - error: Exit value 123 Exit value 0 Any ideas? Thanks, Tomas Ulin #include <sys/types.h> #include <sys/wait.h> #include <pthread.h> #include <signal.h> #include <stdio.h> /* ok - gcc -o tmp tmp.c -L/usr/local/lib -pthread ; ./tmp not ok - gcc -o tmp tmp.c -L/usr/local/lib -llthread ; ./tmp */ void wait_and_display(pid_t pid) { int status; while ( pid != waitpid(pid, &status, 0) ); printf("Exit value %d\n", WEXITSTATUS(status)); } void *athread(void *data) { pthread_exit(0); } int main(void) { pid_t pid; /* Case 1: Explicit call to exit */ if ((pid = fork()) == 0) /* child */ exit(123); /* parent */ wait_and_display(pid); /* Case 2: Start thread and Explicit call to exit */ if ((pid = fork()) == 0) /* child */ { pthread_t thread; pthread_attr_t thread_attr; int result; pthread_attr_init(&thread_attr); result = pthread_create(&thread, &thread_attr, athread, 0); sleep(2); exit(123); } /* parent */ wait_and_display(pid); exit(0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41FEB137.7040402>