gpt4 book ai didi

c++ pthreads - 在尝试锁定互斥锁以进行读取时崩溃

转载 作者:行者123 更新时间:2023-11-28 08:02:35 25 4
gpt4 key购买 nike

LocalT 有其他类的成员实现了 read-write-mutex。 Mutex 在构造函数中初始化,并使用 pthread_rwlock_rdlock(&aMutex); 进行读取锁定。所以,看起来,互斥类没问题。但是,当某些 LocalT 对象锁定其互斥成员以供读取时,程序崩溃了。

CSerialize.cpp:2054 行是 MUTEX.lock_reading();

Thread 6 (Thread 0x80d4e00 (runnable)):
#0 0x4864f11d in pthread_mutex_lock () from /lib/libpthread.so.2
#1 0x4864b558 in pthread_rwlock_init () from /lib/libpthread.so.2
#2 0x4864b659 in pthread_rwlock_rdlock () from /lib/libpthread.so.2
#3 0x0807ae14 in LocalT::serialize (this=0x80d4e00, outbin=@0x7574736b)
at CSerialize.cpp:2054

另外两个正在运行的线程:

1) 在套接字accept();

2) popen() 调用的下一个可运行线程,似乎是从管道执行或读取。但是不知道什么是 __error() ??????

Thread 1 (Thread 0x8614800 (LWP 100343)):
#0 0x4865b8f9 in __error () from /lib/libpthread.so.2
#1 0x4865a15a in pthread_testcancel () from /lib/libpthread.so.2
#2 0x486425bf in read () from /lib/libpthread.so.2
#3 0x08056340 in UT::execute_popen (command=@0x4865e6bc,
ptr_output=0xbf2f7d30) at Utils.cpp:75

3) 所有其他线程休眠。

我不知道它为什么会崩溃?也许有人可以假设或提出建议?

==编辑==

这是一个系统(?)线程(我没有创建它,但程序总是有 +1 个线程)。它总是:

Thread 8 (Thread 0x80d4a00 (LWP 100051)):
#0 0x4865a79b in pthread_testcancel () from /lib/libpthread.so.2
#1 0x48652412 in pthread_mutexattr_init () from /lib/libpthread.so.2
#2 0x489fd450 in ?? ()

==EDIT2 - bt 根据要求==

(gdb) bt
#0 0x4865a7db in pthread_testcancel () from /lib/libpthread.so.2
#1 0x48652412 in pthread_mutexattr_init () from /lib/libpthread.so.2
#2 0x489fd450 in ?? ()

奇怪的是……为什么 ?? () ?

==EDIT3 - 加载核心时==

Program terminated with signal 11, Segmentation fault.
[skiped]
#0 0x4865a7db in pthread_testcancel () from /lib/libpthread.so.2
[New Thread 0x8614800 (LWP 100343)]
[New Thread 0x8614600 (sleeping)]
[New Thread 0x8614400 (sleeping)]
[New Thread 0x8614200 (sleeping)]
[New Thread 0x8614000 (sleeping)]
[New Thread 0x80d4e00 (runnable)]
[New Thread 0x80d4c00 (sleeping)]
[New Thread 0x80d4a00 (LWP 100051)]
[New Thread 0x80d4000 (runnable)]
[New LWP 100802]

(gdb) info thread
* 10 LWP 100802 0x4865a7db in pthread_testcancel () from /lib/libpthread.so.2
9 Thread 0x80d4000 (runnable) 0x486d7bd3 in accept () from /lib/libc.so.6 -- MAIN() THREAD
8 Thread 0x80d4a00 (LWP 100051) 0x4865a79b in pthread_testcancel ()
from /lib/libpthread.so.2 ( UNIDENTIFIED THREAD system()? )
7 Thread 0x80d4c00 (sleeping) 0x48651cb6 in pthread_mutexattr_init ()
from /lib/libpthread.so.2 (SIGNAL PROCESSOR THREAD)
6 Thread 0x80d4e00 (runnable) 0x4864f11d in pthread_mutex_lock ()
from /lib/libpthread.so.2 (MAINTENANCE THREAD)
5 Thread 0x8614000 (sleeping) 0x48651cb6 in pthread_mutexattr_init ()
from /lib/libpthread.so.2 (other mutex cond_wait - worker 1)
4 Thread 0x8614200 (sleeping) 0x48651cb6 in pthread_mutexattr_init ()
from /lib/libpthread.so.2 (other mutex cond_wait - worker 2 )
3 Thread 0x8614400 (sleeping) 0x48651cb6 in pthread_mutexattr_init ()
from /lib/libpthread.so.2 (other mutex cond_wait - worker 3 )
2 Thread 0x8614600 (sleeping) 0x48651cb6 in pthread_mutexattr_init ()
from /lib/libpthread.so.2 (other mutex cond_wait - worker 4)
1 Thread 0x8614800 (LWP 100343) 0x4865b8f9 in __error ()
from /lib/libpthread.so.2 ( popen() thread see below)

我创建了:1 个维护线程(序列化)、1 个 popen() 线程、4 个工作线程、1 个主线程、1 个信号线程 = 8 个线程....

最佳答案

您称为系统线程的线程实际上是您程序的主线程

其次,根据您目前分享的信息,您似乎正在获取互斥量但从未释放它。这会导致不稳定的状态(某些参数具有错误的值),从而导致崩溃。我相信您也会观察到间歇性挂起。

当它崩溃时,你能分享 backtrace 吗?

关于c++ pthreads - 在尝试锁定互斥锁以进行读取时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11042458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com