From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25152 invoked by alias); 23 Nov 2005 11:59:05 -0000 Received: (qmail 25133 invoked by uid 48); 23 Nov 2005 11:59:03 -0000 Date: Wed, 23 Nov 2005 11:59:00 -0000 From: "jordiblasi at gmail dot com" To: glibc-bugs@sources.redhat.com Message-ID: <20051123115902.1913.jordiblasi@gmail.com> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug nptl/1913] New: Thread blocked on sem_wait() does not unwind the C++ stack on thread cancellation. X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00115.txt.bz2 List-Id: /* This simple .cpp source code tests if thread cancellation unwinds the C++ stack. Assuming that C++/NPTL maps cancellation onto a language exception. Shows that threads blocked in sem_wait() do not unwind the C++ stack. However sleep(), pthread_testcancel(), ... behave as expected (throw exception). compiled as g++ nptl_sem_cancel.cpp -lpthread bug description: =============== Thread blocked on sem_wait() does not unwind the C++ stack on thread cancellation. However cancellation is honored. Execution under gdb yields to other conclusions. Thread cancellation lead to SIG32 signal that interrupts sem_wait() system call that terminates the thread. gdb a.out GNU gdb 6.2-2mdk (Mandrakelinux) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i586-mandrake-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) r Starting program: /home/user/a.out [Thread debugging using libthread_db enabled] [New Thread -1210851200 (LWP 19934)] [New Thread -1210852432 (LWP 19937)] Interrupted sem_wait?: Interrupted system call Interrupted sem_wait?: Interrupted system call Program received signal SIG32, Real-time event 32. [Switching to Thread -1210852432 (LWP 19937)] 0xffffe410 in ?? () (gdb) thread apply all bt Thread 2 (Thread -1210852432 (LWP 19937)): #0 0xffffe410 in ?? () #1 0xb7d3daa8 in ?? () #2 0x00000000 in ?? () #3 0x00000000 in ?? () #4 0xb7f66914 in sem_wait@GLIBC_2.0 () from /lib/tls/libpthread.so.0 #5 0xb7f6ba4c in __JCR_LIST__ () from /lib/tls/libpthread.so.0 #6 0x080487ef in cancel_thread () #7 0xb7f62b3c in start_thread () from /lib/tls/libpthread.so.0 #8 0xb7dfe92a in clone () from /lib/tls/libc.so.6 Thread 1 (Thread -1210851200 (LWP 19934)): #0 0xffffe410 in ?? () #1 0xbfc95f58 in ?? () #2 0x00004de1 in ?? () #3 0x00000000 in ?? () #4 0xb7f632e8 in pthread_join () from /lib/tls/libpthread.so.0 #5 0x0804895c in main () #0 0xffffe410 in ?? () (gdb) shared Symbols already loaded for /lib/tls/libpthread.so.0 Symbols already loaded for /usr/lib/libstdc++.so.6 Symbols already loaded for /lib/tls/libm.so.6 Symbols already loaded for /lib/libgcc_s.so.1 Symbols already loaded for /lib/tls/libc.so.6 Symbols already loaded for /lib/ld-linux.so.2 (gdb) environment: ============ uname -a Linux wsc-linux8 2.6.12.6 #3 Wed Oct 5 12:27:21 CEST 2005 i686 Intel(R) Pentium(R) 4 CPU 3.20GHz unknown GNU/Linux g++ --version g++ (GCC) 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk) ldd --version ldd (GNU libc) 2.3.3 ldd ./a.out linux-gate.so.1 => (0xffffe000) libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7f51000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7e7f000) libm.so.6 => /lib/tls/libm.so.6 (0xb7e5c000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e53000) libc.so.6 => /lib/tls/libc.so.6 (0xb7d33000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7f79000) getconf GNU_LIBPTHREAD_VERSION NPTL 2.3.3 */ #include #include #include #include #include #include #include #include sem_t sem; bool canceled; bool calls_destructor; bool exception_thrown; class MyMonitor { public: MyMonitor() {} ~MyMonitor() { calls_destructor = true; } }; void *cancel_thread(void *arg) { try { MyMonitor m; while(true) // sleep(2); // pthread_testcancel(); if(sem_wait(&sem) != 0) printf("Interrupted sem_wait?: %s\n", strerror(errno)); exit(2); } catch (...) { exception_thrown = true; throw; } canceled = false; return NULL; } int main() { pthread_t cancel_thread_id; canceled = calls_destructor = exception_thrown = false; sem_init(&sem,0,0); if ( pthread_create(&cancel_thread_id, NULL, &cancel_thread, NULL) != 0) { printf("Cannot create 'cancel_thread'. %s\n", strerror(errno)); exit(3); } sleep(1); if(pthread_cancel(cancel_thread_id)!=0) { printf("Cannot cancel 'cancel_thread'. %s\n", strerror(errno)); exit(4); } if(pthread_join(cancel_thread_id,NULL) != 0) { printf("Cannot join 'cancel_thread'. %s\n", strerror(errno)); exit(5); } else canceled = true; if(canceled) printf("Thread canceled.\n"); if(calls_destructor) printf("Cancellation calls destructors.\n"); if(exception_thrown) printf("Cancellation throws exception.\n"); return (canceled && calls_destructor && exception_thrown) ? EXIT_SUCCESS : 6; } -- Summary: Thread blocked on sem_wait() does not unwind the C++ stack on thread cancellation. Product: glibc Version: 2.3.3 Status: NEW Severity: normal Priority: P2 Component: nptl AssignedTo: drepper at redhat dot com ReportedBy: jordiblasi at gmail dot com CC: glibc-bugs at sources dot redhat dot com GCC host triplet: i686 Intel(R) Pentium(R) 4 CPU 3.20GHz unknown GNU/Linux 2.6.12. http://sourceware.org/bugzilla/show_bug.cgi?id=1913 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.