我是靠谱客的博主 香蕉长颈鹿,最近开发中收集的这篇文章主要介绍多线程 exit()调用析构函数引发的死锁 附加:gdb调试,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

GlobalObject
exit()
调试代码:

(gdb) l
20
{
21
printf("GlobalObject:~GlobalObject() n");
22
MutexLockGuard lock(mutex_);
23
printf("GlobalObject:~GlobalObject() cleanningn");
24
}
25
26	private:
27
MutexLock mutex_;
28	};
29
(gdb) l
30	GlobalObject g_obj;
31
32	int main()
33	{
34
g_obj.doit();
35	}(gdb)
Line number 36 out of range; exit.cpp has 35 lines.
(gdb) b main
Breakpoint 1 at 0x98c: file exit.cpp, line 34.
(gdb) r
Starting program: /root/study/chapter-4/exit
Breakpoint 1, main () at exit.cpp:34
34
g_obj.doit();
(gdb) b 21
Breakpoint 2 at 0x555555554bb3: file exit.cpp, line 21.
(gdb) b 23
Breakpoint 3 at 0x555555554bd2: file exit.cpp, line 23.
(gdb) l
29
30	GlobalObject g_obj;
31
32	int main()
33	{
34
g_obj.doit();
35	}(gdb)
Line number 36 out of range; exit.cpp has 35 lines.
(gdb) s
GlobalObject::doit (this=0x555555756040 <g_obj>) at exit.cpp:13
13
void doit()
(gdb) s
15
MutexLockGuard lock(mutex_);
(gdb) p mutex
No symbol "mutex" in current context.
(gdb) p mutex_
$1 = {<noncopyable> = {<No data fields>}, mutex_ = {__data = {__lock = 0, __count = 0, __owner = 0, __
__size = '00' <repeats 39 times>, __align = 0}, holder_ = 0}
(gdb) s
MutexLockGuard::MutexLockGuard (this=0x7fffffffe4a0, mutex=...) at mutex.h:41
41
: mutex_(mutex)
(gdb) s
noncopyable::noncopyable (this=0x7fffffffe4a0) at noncopyable.h:6
6
noncopyable() {}
(gdb) s
MutexLockGuard::MutexLockGuard (this=0x7fffffffe4a0, mutex=...) at mutex.h:42
42
{ mutex_.lock(); }
(gdb) s
MutexLock::lock (this=0x555555756040 <g_obj>) at mutex.h:22
22
pthread_mutex_lock(&mutex_);
(gdb) s
pthread_mutex_lock (mutex=0x555555756040 <g_obj>) at forward.c:192
192	forward.c: No such file or directory.
(gdb) s
MutexLock::lock (this=0x555555756040 <g_obj>) at mutex.h:24
24
}
(gdb) s
GlobalObject::doit (this=0x555555756040 <g_obj>) at exit.cpp:16
16
someFunctionMayCallExit();
(gdb) s
someFunctionMayCallExit () at exit.cpp:7
7
exit(1);
(gdb) p errno
$2 = 0
(gdb) s
__GI_exit (status=1) at exit.c:139
139	exit.c: No such file or directory.
(gdb) p errno
$3 = 0
(gdb) s
138	in exit.c
(gdb) s
139	in exit.c
(gdb) bt
#0
__GI_exit (status=1) at exit.c:139
#1
0x0000555555554988 in someFunctionMayCallExit () at exit.cpp:7
#2
0x0000555555554b75 in GlobalObject::doit (this=0x555555756040 <g_obj>) at exit.cpp:16
#3
0x0000555555554998 in main () at exit.cpp:34
(gdb) p mutex_
No symbol "mutex_" in current context.
(gdb) s
__run_exit_handlers (status=1, listp=0x7ffff7a46718 <__exit_funcs>, run_list_atexit=run_list_atexit@en
40	in exit.c
(gdb) p errno
$4 = 0
(gdb) p AccountA_mutex
No symbol "AccountA_mutex" in current context.
(gdb) info threads
Id
Target Id
Frame
* 1
process 1039 "exit" __run_exit_handlers (status=1, listp=0x7ffff7a46718 <__exit_funcs>,
run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:40
(gdb) pstack 1039
Undefined command: "pstack".
Try "help".
(gdb) quit

最后

以上就是香蕉长颈鹿为你收集整理的多线程 exit()调用析构函数引发的死锁 附加:gdb调试的全部内容,希望文章能够帮你解决多线程 exit()调用析构函数引发的死锁 附加:gdb调试所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部