免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 38655 | 回复: 0

[其他] c调用lua出现死锁问题 [复制链接]

论坛徽章:
0
发表于 2019-08-23 14:45 |显示全部楼层
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.redhat.com/show_bug.cgi?id=906468

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

哪位大神赐教,不胜感激!!

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP