分享

pthread

 sven_ 2013-08-01
谢谢hoyt,照您的方法程序有了正确的输出,不过我还是想知道原来的程序的问题具体出在哪里,以下是程序改动前的部分调试结果:
(gdb) break 35
Breakpoint 1 at 0x80485b6: file thrdcancel.c, line 35.
//停止在pthread_join(thrd2,NULL);
(gdb) run
Starting program: /root/process/thrdcancel
[New Thread 1073963648 (LWP 2822)]
[New Thread 1082354880 (LWP 2829)]
[New Thread 1090743360 (LWP 2830)]
task1 count: 0
[Switching to Thread 1073963648 (LWP 2822)]

Breakpoint 1, main (argc=1, argv=0xbfffdeb4) at thrdcancel.c:35
35 pthread_join(thrd2,NULL);
(gdb) si
0x080485b9 35 pthread_join(thrd2,NULL);
(gdb) info thr
3 Thread 1090743360 (LWP 2830) 0xffffe002 in ?? ()
2 Thread 1082354880 (LWP 2829) 0xffffe002 in ?? ()
* 1 Thread 1073963648 (LWP 2822) 0x080485b9 in main (argc=1, argv=0xbfffdeb4)
at thrdcancel.c:35
(gdb) set step-mode on
(gdb) si
task2 count: 0
task2 count: 1
task2 count: 2
task2 count: 3
task2 count: 4
task1 count: 1
0x080485bb 35 pthread_join(thrd2,NULL);
(gdb) info thr
3 Thread 1090743360 (LWP 2830) 0x4002cec0 in __nptl_death_event ()
from /lib/tls/libpthread.so.0
2 Thread 1082354880 (LWP 2829) 0xffffe002 in ?? ()
* 1 Thread 1073963648 (LWP 2822) 0x080485bb in main (argc=1, argv=0xbfffdeb4)
at thrdcancel.c:35
(gdb) si
task1 count: 2
0x080485be 35 pthread_join(thrd2,NULL);
(gdb) info thr
3 Thread 1090743360 (LWP 2830) 0x4002cec0 in __nptl_death_event ()
from /lib/tls/libpthread.so.0
2 Thread 1082354880 (LWP 2829) 0xffffe002 in ?? ()
* 1 Thread 1073963648 (LWP 2822) 0x080485be in main (argc=1, argv=0xbfffdeb4)
at thrdcancel.c:35
(gdb) thr 2
[Switching to thread 2 (Thread 1082354880 (LWP 2829))]#0 0xffffe002 in ?? ()
(gdb) si
0x420ac5b6 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5b8 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5bb in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420eb5c0 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5c1 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5c4 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5c6 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5c7 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5c9 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5d0 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5d7 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5d9 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5dc in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5de in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5e0 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5e2 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5ea in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5ed in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5ef in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5f1 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5f2 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420eb5f3 in __libc_disable_asynccancel () from /lib/tls/libc.so.6
(gdb)
0x420ac5c0 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5c1 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5c6 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5c9 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x421132e3 in __i686.get_pc_thunk.cx () from /lib/tls/libc.so.6
(gdb)
0x421132e6 in __i686.get_pc_thunk.cx () from /lib/tls/libc.so.6
(gdb)
0x420ac5ce in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5d4 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5da in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5dc in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5de in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5e2 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5e5 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac5c8 in nanosleep () from /lib/tls/libc.so.6
(gdb)
0x420ac429 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac42b in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac42d in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac42f in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac435 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac43b in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac442 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac445 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac447 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac44a in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac44c in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac452 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac454 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac455 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac456 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac457 in sleep () from /lib/tls/libc.so.6
(gdb)
0x420ac458 in sleep () from /lib/tls/libc.so.6
(gdb)
0x0804867d in task1 (counter=0x804983c) at thrdcancel.c:62
62 sleep(1);
(gdb)
0x08048680 62 sleep(1);
(gdb)
57 while(*counter < 5)
(gdb)
0x08048652 57 while(*counter < 5)
(gdb)
0x08048655 57 while(*counter < 5)
(gdb)
60 printf("task1 count: %d ",*counter);
(gdb)
0x0804865c 60 printf("task1 count: %d ",*counter);
(gdb)
0x0804865f 60 printf("task1 count: %d ",*counter);
(gdb)
0x08048661 60 printf("task1 count: %d ",*counter);
(gdb)
0x08048666 60 printf("task1 count: %d ",*counter);
(gdb)
0x08048450 in printf ()
(gdb)
0x4204f0e0 in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0e1 in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0e3 in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0e6 in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0e9 in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0ec in printf () from /lib/tls/libc.so.6
(gdb)
0x4204f0ef in printf () from /lib/tls/libc.so.6
(gdb)
0x420153bd in __i686.get_pc_thunk.bx () from /lib/tls/libc.so.6
(gdb)
0x420153c0 in __i686.get_pc_thunk.bx () from /lib/tls/libc.so.6

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多