Subj : Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join To : comp.programming.threads From : Daniele Date : Thu Aug 18 2005 07:52 pm annamalai.gurusami@gmail.com wrote: > Hi All, > > I am having a problem related to pthread_join. The following short > program > demonstrates the problem. > > There are two threads of execution involved. The main program (A) and > another > thread (B). The thread B runs continuously (in forever loop) doing its > work. > Every time in the loop, it once call pthread_testcancel to check if it > has to > continue or not. This is its only cancellation point. No, it isn't. cout << something will call write() sooner or later, and that's a cancellation point. This is true for printf() too. It's a problem with stack unwinding, as already suggested, but I'm not sure it's a bug or not. Anyway, cancellation doesn't work well with c++, try to avoid it if you can. Below there's the output of the program on my computer. Regards, Daniele On my system (Debian sid, linux kernel 2.6.11.7, Athlon XP 2.6 barton, libc6 2.3.5, NPTL, libstdc++5 3.3.5), this is the output of the program: $ g++ -g3 -o test_atexit_cancel test_atexit_cancel.cpp -lpthread $ ./test_atexit_cancel FATAL: exception not rethrown testcancel() Aborted $ gdb test_atexit_cancel GNU gdb 6.1-debian 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 "i386-linux"...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) r Starting program: /home/aslo/src/test_atexit_cancel [Thread debugging using libthread_db enabled] [New Thread -1210383264 (LWP 2983)] [New Thread -1210385488 (LWP 2986)] FATAL: exception not rethrown testcancel() Program received signal SIGABRT, Aborted. [Switching to Thread -1210385488 (zombie)] 0xb7dd983b in raise () from /lib/tls/libc.so.6 (gdb) bt #0 0xb7dd983b in raise () from /lib/tls/libc.so.6 #1 0xb7ddafa2 in abort () from /lib/tls/libc.so.6 #2 0xb7fd52f8 in unwind_cleanup () from /lib/tls/libpthread.so.0 #3 0x0804a070 in ?? () #4 0xb7dafa28 in ?? () #5 0xb7eeab18 in _Unwind_DeleteException () from /lib/libgcc_s.so.1 #6 0xb7fcb000 in ?? () #7 0xb7ff5bd0 in _dl_map_object_deps () from /lib/ld-linux.so.2 #8 0xb7f4ab8a in ?? () from /usr/lib/libstdc++.so.5 #9 0xb7f4ab9a in ?? () from /usr/lib/libstdc++.so.5 #10 0xb7f4abaa in ?? () from /usr/lib/libstdc++.so.5 #11 0xb7f4abba in ?? () from /usr/lib/libstdc++.so.5 #12 0xb7f4abca in ?? () from /usr/lib/libstdc++.so.5 #13 0xb7f4abda in ?? () from /usr/lib/libstdc++.so.5 #14 0xb7f4abea in ?? () from /usr/lib/libstdc++.so.5 #15 0xb7f4abfa in ?? () from /usr/lib/libstdc++.so.5 #16 0xb7f4ac0a in ?? () from /usr/lib/libstdc++.so.5 #17 0xb7f4ac1a in ?? () from /usr/lib/libstdc++.so.5 #18 0xb7f4ac2a in ?? () from /usr/lib/libstdc++.so.5 #19 0xb7f4ac3a in ?? () from /usr/lib/libstdc++.so.5 #20 0xb7f4ac4a in ?? () from /usr/lib/libstdc++.so.5 #21 0xb7f4ac5a in ?? () from /usr/lib/libstdc++.so.5 #22 0xb7f4ac6a in ?? () from /usr/lib/libstdc++.so.5 #23 0xb7f4ac7a in ?? () from /usr/lib/libstdc++.so.5 #24 0xb7f4ac8a in ?? () from /usr/lib/libstdc++.so.5 #25 0xb7f4ac9a in ?? () from /usr/lib/libstdc++.so.5 #26 0xb7f4acaa in ?? () from /usr/lib/libstdc++.so.5 #27 0xb7f59d60 in std::basic_ios >::basic_ios () from /usr/lib/libstdc++.so.5 Previous frame inner to this frame (corrupt stack?) (gdb) .