From owner-freebsd-threads@FreeBSD.ORG Mon Jan 31 21:29:37 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6CF4916A4CE for ; Mon, 31 Jan 2005 21:29:37 +0000 (GMT) Received: from mailgate-a.mysql.com (mailgate1.mysql.com [213.115.162.47]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5CA3143D64 for ; Mon, 31 Jan 2005 21:29:36 +0000 (GMT) (envelope-from tomas@mysql.com) Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgate-a.mysql.com (8.13.2/8.13.1) with ESMTP id j0VLTDfP013043 for ; Mon, 31 Jan 2005 22:29:13 +0100 Received: from mail.mysql.com ([10.222.1.99]) by localhost (mailgate-a [10.222.1.98]) (amavisd-new, port 10026) with LMTP id 12612-04 for ; Mon, 31 Jan 2005 22:29:13 +0100 (CET) Received: from mysql.com (c-ab59e255.525-1-64736c12.cust.bredbandsbolaget.se [85.226.89.171]) (authenticated bits=0) by mail.mysql.com (8.12.10/8.12.10) with ESMTP id j0VLTSwZ002550 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 31 Jan 2005 22:29:29 +0100 Message-ID: <41FEB137.7040402@mysql.com> Date: Mon, 31 Jan 2005 23:29:11 +0100 From: Tomas Ulin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040520 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-threads@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailgate.mysql.com Subject: wrong exit code with linux threads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 21:29:37 -0000 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 #include #include #include #include /* 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); }