本文主要是介绍localtime的死锁问题及规避方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
1、分析进程死锁原因
2、解决进程死锁问题
开发webrtc服务端录制时,录制中出现偶现死锁问题,导致一个用户的录制线程始终无法正常退出,录制进程一直残留在服务器上。
1、分析线程死锁原因
通过pstack 进程id 查看进程堆栈,发现如下堆栈信息:
#0 __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
#1 0x00007f7690c0894a in _L_lock_10416 () from /lib64/libc.so.6
#2 0x00007f7690c062b5 in __GI___libc_malloc (bytes=140144917086240, bytes@entry=56) at malloc.c:2852
#3 0x00007f7691d9777e in _dl_map_object_deps (map=map@entry=0x7f7691fa2000, preloads=preloads@entry=0x0, npreloads=npreloads@entry=0, trace_mode=trace_mode@entry=0, open_mode=open_mode@entry=-2147483648) at dl-deps.c:511
#4 0x00007f7691d9d88c in dl_open_worker (a=a@entry=0x7f762d7f8958) at dl-open.c:261
#5 0x00007f7691d996c4 in _dl_catch_error (objname=objname@entry=0x7f762d7f8948, errstring=errstring@entry=0x7f762d7f8950, mallocedp=mallocedp@entry=0x7f762d7f8947, operate=operate@entry=0x7f7691d9d780 <dl_open_worker>, args=args@entry=0x7f762d7f8958) at dl-error.c:177
#6 0x00007f7691d9d24b in _dl_open (file=0x7f7690ced0a6 "libgcc_s.so.1", mode=-2147483647, caller_dlopen=<optimized out>, nsid=-2, argc=16, argv=0x7fffc6c85118, env=0x23ca1d0) at dl-open.c:650
#7 0x00007f7690ca6742 in do_dlopen (ptr=ptr@entry=0x7f762d7f8b70) at dl-libc.c:87
#8 0x00007f7691d996c4 in _dl_catch_error (objname=0x7f762d7f8b50, errstring=0x7f762d7f8b58, mallocedp=0x7f762d7f8b4f, operate=0x7f7690ca6700 <do_dlopen>, args=0x7f762d7f8b70) at dl-error.c:177
#9 0x00007f7690ca67df in dlerror_run (operate=operate@entry=0x7f7690ca6700 <do_dlopen>, args=args@entry=0x7f762d7f8b70) at dl-libc.c:46
#10 0x00007f7690ca6851 in __GI___libc_dlopen_mode (name=name@entry=0x7f7690ced0a6 "libgcc_s.so.1", mode=mode@entry=-2147483647) at dl-libc.c:163
#11 0x00007f7690c7dff5 in init () at ../sysdeps/x86_64/backtrace.c:52
#12 0x00007f7690f43953 in pthread_once () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S:103
#13 0x00007f7690c7e10c in __GI___backtrace (array=array@entry=0x7f762d7f8c10, size=size@entry=64) at ../sysdeps/x86_64/backtrace.c:103
#14 0x00007f7690ba9d12 in backtrace_and_maps (do_abort=<optimized out>, do_abort@entry=2, written=<optimized out>, fd=fd@entry=2) at ../sysdeps/unix/sysv/linux/libc_fatal.c:47
#15 0x00007f7690bfd40f in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7f7690cf26a8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:172
#16 0x00007f7690c02c7e in malloc_printerr (action=3, str=0x7f7690cf2a40 "malloc(): memory corruption (fast)", ptr=<optimized out>) at malloc.c:4895
#17 0x00007f7690c04e8b in _int_malloc (av=av@entry=0x7f7608000020, bytes=bytes@entry=15) at malloc.c:3289
#18 0x00007f7690c062c0 in __GI___libc_malloc (bytes=bytes@entry=15) at malloc.c:2855
#19 0x00007f7690c0bd5a in __GI___strdup (s=0x7f7690ceed59 "/etc/localtime") at strdup.c:42
#20 0x00007f7690c3282d in tzset_internal (always=<optimized out>, explicit=explicit@entry=1) at tzset.c:441
#21 0x00007f7690c32b63 in __tz_convert (timer=0x7f762d7f9628, use_localtime=1, tp=0x7f7690f35580 <_tmbuf>) at tzset.c:629
在localtime中出现了死锁问题
2、解决线程死锁问题
因为是系统函数,这里比较彻底的方式是替换localtime函数。采用gmtime获取系统时间。
这篇关于localtime的死锁问题及规避方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!