This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/1913] Thread blocked on sem_wait() does not unwind the C++ stack on thread cancellation.


------- Additional Comments From jorge dot monteagudo at gmail dot com  2005-12-05 09:32 -------
I think I've found a workaround ! 

I've tested on my mandrake 10.1 with success. I've changed the 'sem_wait'
with a 'sem_timedwait', trying to emulate it with a big timeout. The thread
code now is:

void *cancel_thread(void *arg) { 
    timespec delay;
    struct timeval now;
      
    try {   
        MyMonitor m; 
        
        printf("loop...\n"); 
        while(!bSalir) {

              gettimeofday( &now, 0 );
              delay.tv_sec = now.tv_sec + 200;
              delay.tv_nsec = 0;
              if( sem_timedwait(&sem, &delay) != 0 ) {
                 printf("Interrupted sem_timedwait?: %s\n", strerror(errno)); 
              }
              printf("wait ended!!\n"); */
        } 
        printf("end loop\n"); 
        exit(2); 
             
    } catch (...) { 
        exception_thrown = true; 
        throw; 
    }
     
    canceled = false; 
    return NULL; 
} 

and the results:

$ ./a.out
loop...
Thread canceled.
Cancellation calls destructors.
Cancellation throws exception.

$ uname -a
Linux xxxx 2.6.9 #4 Tue Nov 16 09:22:59 CET 2004 i686 Intel(R) Pentium(R) 4 CPU
3.00GHz unknown GNU/Linux

$ g++ --version
g++ (GCC) 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ldd --version
ldd (GNU libc) 2.3.3
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

$ ldd ./a.out
        linux-gate.so.1 =>  (0xffffe000)
        libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7fc2000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7ef0000)
        libm.so.6 => /lib/tls/libm.so.6 (0xb7ecd000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7ec4000)
        libc.so.6 => /lib/tls/libc.so.6 (0xb7da4000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fec000)

$ getconf GNU_LIBPTHREAD_VERSION
NPTL 2.3.3

$ 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 -1210437504 (LWP 6078)]
[New Thread -1210438736 (LWP 6081)]
loop...
Interrupted sem_timedwait?: Interrupted system call
Interrupted sem_timedwait?: Interrupted system call

Program received signal SIG32, Real-time event 32.
[Switching to Thread -1210438736 (LWP 6081)]
0xffffe410 in ?? ()
Current language:  auto; currently c
(gdb) thread apply all bt

Thread 2 (Thread -1210438736 (LWP 6081)):
#0  0xffffe410 in ?? ()
#1  0xb7da2aa8 in ?? ()
#2  0x00000000 in ?? ()
#3  0x00000000 in ?? ()
#4  0xb7fcba67 in sem_timedwait () from /lib/tls/libpthread.so.0
#5  0x0804887f in cancel_thread (arg=0x0) at nptl_sem_cancel.cpp:314
#6  0xb7fc7b3c in start_thread () from /lib/tls/libpthread.so.0
#7  0xb7e6392a in clone () from /lib/tls/libc.so.6

Thread 1 (Thread -1210437504 (LWP 6078)):
#0  0xffffe410 in ?? ()
#1  0xbfffed58 in ?? ()
#2  0x000017c1 in ?? ()
#3  0x00000000 in ?? ()
#4  0xb7fc82e8 in pthread_join () from /lib/tls/libpthread.so.0
#5  0x08048a08 in main () at nptl_sem_cancel.cpp:358
#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) c
Continuing.
[Thread -1210438736 (zombie) exited]
Thread canceled.
Cancellation calls destructors.
Cancellation throws exception.

Program exited normally.


I hope this could help to clarify this bug.

regards,
Jorge

-- 


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]