标题:c调用lua出现死锁问题
取消只看楼主
lilw
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-8-23
 问题点数:0 回复次数:0 
c调用lua出现死锁问题
c程序中使用lua5.3.2库来实现程序与lua脚本的调用,设计概要:
1. 多线程调用lua的接口来实现对lua脚本的调用
2. 多线程调用system实现其他任务

这样做概率性的会出现程序死锁问题,下面是部分的堆栈信息:

Thread 8 (Thread 0x7f7ae46f0700 (LWP 14392)):
#0  0x00007f7b7ab03d1c in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x00007f7b7aa7653d in _L_lock_121 () from /lib64/libc.so.6
#2  0x00007f7b7aa74103 in __GI__IO_un_link () from /lib64/libc.so.6
#3  0x00007f7b7aa6611d in fclose@@GLIBC_2.2.5 () from /lib64/libc.so.6
#4  0x000000000046b2db in io_fclose ()
#5  0x000000000045c1dc in luaD_precall ()
#6  0x00000000004665a5 in luaV_execute ()
#7  0x000000000045c59c in luaD_call ()
#8  0x000000000045b75b in luaD_rawrunprotected ()
#9  0x000000000045b7e3 in luaD_pcall ()
#10 0x00000000004595f2 in lua_pcallk ()
#11 0x0000000000429638 in LuaHandler::dataAssemble_ex (this=0x7f7ae46efd40, pDataList=0x7f7a7c03c030, pResult=0x7f7ae46efd00, mapTaskRunResult=std::map with 0 elements, mapUpdateData=std::map with 0 elements, listSendPath=empty std::list, mapTaskHighsPot=std::map with 0 elements) at ../src/LuaHandler.cpp:387
#12 0x0000000000418dc6 in DataAssembler::dataAssemble (this=0x117b770, key="wsms_dns_hijacking_map", pDataList=0x7f7a7c03c030) at ../src/DataAssembler.cpp:323
#13 0x000000000041961b in DataAssembler::executeDataAssemble (this=0x7f7b7adc09e0 <list_all_lock>, strKey=<error reading variable: Cannot access memory at address 0x80>, pDataList=0x7f7ae46f0700) at ../src/DataAssembler.cpp:227
#14 0x00000000004198a1 in DataAssembler::dataAssembleCallBack (data=<optimized out>, user_data=<optimized out>) at ../src/DataAssembler.cpp:239
#15 0x00007f7b7b86fe7c in g_thread_pool_thread_proxy () from /lib64/libglib-2.0.so.0
#16 0x00007f7b7b86f4f5 in g_thread_proxy () from /lib64/libglib-2.0.so.0
#17 0x00007f7b7adccdd5 in start_thread () from /lib64/libpthread.so.0
#18 0x00007f7b7aaf602d in clone () from /lib64/libc.so.6

Thread 4 (Thread 0x7f7ae26ec700 (LWP 14396)):
#0  0x00007f7b7ab03d1c in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x00007f7b7aa76640 in _L_lock_4452 () from /lib64/libc.so.6
#2  0x00007f7b7aa75a08 in _IO_flush_all_lockp () from /lib64/libc.so.6
#3  0x000000000046ba63 in io_popen ()
#4  0x000000000045c1dc in luaD_precall ()
#5  0x00000000004665a5 in luaV_execute ()
#6  0x000000000045c59c in luaD_call ()
#7  0x000000000045b75b in luaD_rawrunprotected ()
#8  0x000000000045b7e3 in luaD_pcall ()
#9  0x00000000004595f2 in lua_pcallk ()
#10 0x0000000000429252 in LuaHandler::parseConfigure (this=0x7f7ae26ebac0, filename=0x7f7adc09f8c8 "/usr/local/ms-eagle-rcc/conf/wsms/dns_local_domain", spTaskType=...) at ../src/LuaHandler.cpp:85
#11 0x00000000004393dc in TaskConfigure::executeScript (this=<optimized out>, script="/usr/local/ms-eagle-rcc/script/wsms/parseConfigureDns_dns_local_domain.lua", configFilename="/usr/local/ms-eagle-rcc/conf/wsms/dns_local_domain", pLogger=<optimized out>, spTaskType=...) at ../src/TaskConfigure.cpp:105
#12 0x000000000043989b in TaskConfigure::parseConfigure (this=0x11188c0, spTaskType=...) at ../src/TaskConfigure.cpp:75
#13 0x0000000000439e7c in TaskConfigure::parseConfigure (this=0x11188c0, pSchedulerConfig=0x7f7ae26ebca0) at ../src/TaskConfigure.cpp:43
#14 0x0000000000437844 in SchedulerHandler::updateConf (this=0x1118670, schedulerInfo=...) at ../src/SchedulerHandler.cpp:568
#15 0x0000000000437b8e in SchedulerHandler::run (this=0x7f7a50001a00) at ../src/SchedulerHandler.cpp:148
#16 0x00000000004cb9a0 in Poco::ThreadImpl::runnableEntry(void*) ()
#17 0x00007f7b7adccdd5 in start_thread () from /lib64/libpthread.so.0
#18 0x00007f7b7aaf602d in clone () from /lib64/libc.so.6

Thread 181 (Thread 0x7f7b3af9d700 (LWP 14197)):
#0  0x00007f7b7ab03d1c in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x00007f7b7aa76728 in _L_lock_6097 () from /lib64/libc.so.6
#2  0x00007f7b7aa7647f in __GI__IO_list_lock () from /lib64/libc.so.6
#3  0x00007f7b7aabd087 in fork () from /lib64/libc.so.6
#4  0x000000000044a302 in systemEx (cmdstring=0x7f7ad0009008 "/usr/local/ms-eagle-wstools/bin/wspoll -f /usr/local/ms-eagle-rcc/data/wsms_poll_100k_appa.in -o /usr/local/ms-eagle-rcc/data/wsms_poll_100k_appa.out", timeout=600) at ../src/util/ToolsUtil.cpp:135
#5  0x0000000000412f20 in BatchJobExecutor::runCmd (this=<optimized out>, cmd="/usr/local/ms-eagle-wstools/bin/wspoll -f /usr/local/ms-eagle-rcc/data/wsms_poll_100k_appa.in -o /usr/local/ms-eagle-rcc/data/wsms_poll_100k_appa.out", iTimeout=989452032, pLogger=0xffffffffffffffff) at ../src/BatchJobExecutor.cpp:146
#6  0x0000000000413f1e in BatchJobExecutor::executeTask (this=0x11f1660, spJobInfo=..., spExecutingTask=...) at ../src/BatchJobExecutor.cpp:69
#7  0x0000000000420970 in JobExecutorWrapper::executeBatchTask (this=0x1146800, spJobInfo=..., spExecutingTask=...) at ../src/JobExecutorWrapper.cpp:198
#8  0x0000000000422319 in JobExecutorWrapper::batchTaskCallbackWrapper (data=<optimized out>, user_data=<optimized out>) at ../src/JobExecutorWrapper.cpp:127
#9  0x00007f7b7b86fe7c in g_thread_pool_thread_proxy () from /lib64/libglib-2.0.so.0
#10 0x00007f7b7b86f4f5 in g_thread_proxy () from /lib64/libglib-2.0.so.0
#11 0x00007f7b7adccdd5 in start_thread () from /lib64/libpthread.so.0
#12 0x00007f7b7aaf602d in clone () from /lib64/libc.so.6

经过定位,io_popen调用了l_popen
#define l_popen(L,c,m)        (fflush(NULL), popen(c,m))

问题就在这句 fflush(NULL),这是这个操作导致了死锁(参考 : https://bugzilla.

我的修改方案就是直接将 fflush(NULL)这句去掉,这样做会不会有什么风险?

哪位大神赐教,不胜感激!!
搜索更多相关主题的帖子: from this cpp out local 
2019-08-23 15:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-496521-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.342832 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved