读写锁unlock时产生死锁
最近使用读写锁的时候遇到了一个奇怪的死锁现象:调用pthread_rwlock_unlock竟然阻塞了。
堆栈:
(gdb) t 10
[Switching to thread 10 (Thread 0x7ffd621fc700 (LWP 17864))]#0 0x000000363b80e054 in __lll_lock_wait () from /lib64/libpthread.so.0
(gdb) bt
#0 0x000000363b80e054 in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x000000363b80ae90 in pthread_rwlock_unlock () from /lib64/libpthread.so.0
#2 0x000000000040e2b9 in OutboundServer::OutbdExcute (this=0x80, outbd_uuid=..., app_name=..., app_arg=..., app_exe_uuid=..., event_lock=253) at ../os/mutex.h:64
#3 0x0000000000413234 in IxApi::execute_lua (this=0x17b7350, lua_name=..., lua_arg=..., cuid=..., event_lock=false) at ixapi.cpp:1089
#4 0x00007ffd8f55b42c in TelMgr::play_agent_num (this=0x17bb920, cuid=..., language=..., agent_num=...) at TelMgr.cpp:2790
#5 0x00007ffd8f574bb8 in QueueMgr::OnEvent_Answer (this=0x17ce780, msg=0x17ce788) at ../queue_and_acd/QueueMgr.cpp:876
#6 0x00007ffd8f57528c in QueueMgr::processMsg (this=0x17ce780, event=0x80) at ../queue_and_acd/QueueMgr.cpp:473
#7 0x00007ffd8f5755a7 in QueueMgrThread::run (this=0x17d1f40) at ../queue_and_acd/QueueMgr.cpp:421
#8 0x000000000042a717 in util::Thread::threadFun (this=0x17d1f40) at thread.cpp:92
#9 0x000000000042a4aa in util::Thread::begin (pArg=0x7ffd8802ae78) at thread.cpp:35
#10 0x000000363b807851 in start_thread () from /lib64/libpthread.so.0
#11 0x000000363b0e890d in clone () from /lib64/libc.so.6
代码:
std::string OutboundServer::OutbdExcute(const string outbd_uuid,const std :: string app_name,const std :: string app_arg,const std :: string app_exe_uuid,bool event_lock)
{
Oubound_handle_t *handle = ListenThread->otbdConnections.find(outbd_uuid);
if(!handle)
{
TelError<<"Error,cann't find the handle of outbd_uuid:"<<outbd_uuid<<",app_name:"<<app_name<<",arg:"<<app_arg<<",app_exe_uuid:"<<app_exe_uuid<<",event_lock:"<<event_lock;
return "-1";
}
TelTrace<<"find handle,handlenum:"<<handle->handle->sock<<",execute app:"<<app_name<<",arg:"<<app_arg<<",app_exe_uuid:"<<app_exe_uuid<<",event_lock:"<<event_lock;
util::MutexLock lock(handle->handle_Guard);
if(event_lock)
handle->handle->event_lock = 1;
else
handle->handle->event_lock = 0;
if(ESL_SUCCESS!=esl_execute(handle->handle,app_name.c_str(),app_arg.c_str(),app_exe_uuid.c_str()))
return "-1";
if(!handle->handle->last_sr_reply)
return "-1";
return handle->handle->last_sr_reply;
}
这个锁是类内部的锁,且只有一个函数使用(会存在多线程的情况,所以加了锁),且使用的地方是自动锁,所以好奇问一下大家有没有遇到这样的问题?大概会是什么原因?谢谢!