From owner-freebsd-threads@FreeBSD.ORG Thu Jul 8 05:15:04 2004 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 6685216A4CE for ; Thu, 8 Jul 2004 05:15:04 +0000 (GMT) Received: from anor.ics.muni.cz (anor.ics.muni.cz [147.251.4.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id BC9B643D31 for ; Thu, 8 Jul 2004 05:15:03 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (w54-183.fi.muni.cz [147.251.54.183]) (user=hopet@META mech=LOGIN bits=0) by anor.ics.muni.cz (8.12.1/8.12.1) with ESMTP id i685F1nD031555 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Thu, 8 Jul 2004 07:15:02 +0200 From: "Petr Holub" To: "Daniel Eischen" Date: Thu, 8 Jul 2004 07:14:59 +0200 Message-ID: <007d01c464aa$840deea0$b736fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 In-Reply-To: Importance: Normal X-Muni-Spam-TestIP: 147.251.54.183 X-Muni-Virus-Test: Clean cc: threads@freebsd.org Subject: RE: sem_wait as cancellation point 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: Thu, 08 Jul 2004 05:15:04 -0000 > sem_wait() is a cancellation point in libpthread. No, it is not - at least according to my experience of 5.2.1-RELEASE-p9. When I use following snipplet of code, it keeps hanging in the pthread_join: ---------------------------------------------------------------- /* Example to demonstate non-cancellable behavior of sem_wait in phtread * environment. I've tested it on FreeBSD 5.2.1-RELEASE-p9 and the program * was compiled using: * cc -D_THREAD_SAFE -o sem_wait sem_wait.c -pthread -lc_r */ #include #include #include #include pthread_t test_thread; sem_t my_semaphore; void * testsem (void *data) { printf("Initing semaphore.\n"); sem_init(&my_semaphore, 0, 0); printf("Posting semaphore.\n"); sem_post(&my_semaphore); printf("Waiting for semaphore (this should pass).\n"); sem_wait(&my_semaphore); printf("Waiting for semaphore (this should hang).\n"); sem_wait(&my_semaphore); printf("Got over sem_wait - strange.\n"); } int main() { void *thread_result; printf("Creating thread.\n"); pthread_create(&test_thread, NULL, testsem, (void *) NULL); printf("Sleeping for 5 secs.\n"); sleep(3); printf("Trying to cancel the thread.\n"); pthread_cancel(test_thread); sleep(1); printf("Trying to join the thread.\n"); pthread_join(test_thread, &thread_result); printf("Finished.\n"); return(EXIT_SUCCESS); } ---------------------------------------------------------------- Am I doing something wrong? Thanks, Petr ================================================================ Petr Holub CESNET z.s.p.o. Supercomputing Center Brno Zikova 4 Institute of Compt. Science 162 00 Praha 6, CZ Masaryk University Czech Republic Botanicka 68a, 60200 Brno, CZ e-mail: Petr.Holub@cesnet.cz phone: +420-549493944 fax: +420-541212747 e-mail: hopet@ics.muni.cz