[英]Abort While accessing a vector
我寫了一個運行的程序
上面列表中的 1 和 3 是兩個不同的實例,可以重疊。
給麻煩的函數簽名。
bool ProcessInfoHandler::getCPUInfo (rsc::ProcInfo &procInfo, bool isThreadCall)
在運行程序大約 3 天后,我遇到了下面提到的崩潰。
#2 0x000000000041fdb8 in sn_sig_handler (signum=6, siginfo=0x451a7d80, undocumented= <value optimized out>) at common/main/sn_proc_main.cpp:109
#3 <signal handler called>
#4 0x00000031d9630265 in raise () from /lib64/libc.so.6
#5 0x00000031d9631d10 in abort () from /lib64/libc.so.6
#6 0x00000031d966a84b in __libc_message () from /lib64/libc.so.6
#7 0x00000031d967230f in _int_free () from /lib64/libc.so.6
#8 0x00000031d967276b in free () from /lib64/libc.so.6
#9 0x00000000004367a5 in deallocate (this=0x66cff0, __position=..., __x=<value optimized out>)
at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:94
#10 _M_deallocate (this=0x66cff0, __position=..., __x=<value optimized out>) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:133
#11 std::vector<cpu_instance_data_t, std::allocator<cpu_instance_data_t> >::_M_insert_aux (this=0x66cff0, __position=..., __x=<value optimized out>)
at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:299
#12 0x0000000000431f8e in ProcessInfoHandler::getCPUInfo (this=<value optimized out>, procInfo=..., isThreadCall=false)
at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:610
#13 0x00000000004333be in ProcessInfoHandler::getProcessInformation (this=0xc16f9c0, procInfoSeq=..., isThreadCall=false) at processinfohandler.cc:255
由於專有原因,無法給出getCPUInfo
的代碼。 請建議是否有相同的解決方法。
對std::vector<>::_M_insert_aux()
的調用表明該向量正在getCPUInfo
被修改 - 如果此代碼可以被並發調用(在多個線程上),這是您的“3 列表”所暗示的,那么您需要擁有諸如互斥鎖之類的東西來同步線程。
std::vector
不是線程安全的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.