我有一個應用程序正在運行多個線程。我有2個線程在嘗試分配std :: string時看起來死鎖。檢查兩個線程的回溯表明,在某些時候,人們試圖分配一個std :: string,並得到一個bad_alloc異常。在它的catch塊中,創建另一個字符串以嘗試將調用堆棧寫入某個日誌文件。同時,另一個線程也試圖分配一個std :: string,然後整個過程都卡住了。當分配一個std :: string時發生死鎖
這裏有2個陷入僵局線程的相關部分:
#0 0x004cf7a2 in _dl_sysinfo_int80() from /lib/ld-linux.so.2
#1 0x034ba3de in __lll_mutex_lock_wait() from /lib/tls/libpthread.so.0
#2 0x034b700b in _L_mutex_lock_35() from /lib/tls/libpthread.so.0
#3 0x004e5fd4 in ??() from /lib/ld-linux.so.2
#4 0x07c9f9bc in ??() from /.../libstdc++.so.5
#5 0x00000037 in ??()
#6 0x07ca1714 in std::__default_alloc_template<true, 0>::_S_free_list() from /.../libstdc++.so.5
#7 0x9b2223a8 in ??()
#8 0x07c6ab7e in std::__default_alloc_template<true, 0>::allocate() from /.../libstdc++.so.5
#9 0x07c6ab7e in std::__default_alloc_template<true, 0>::allocate() from /.../libstdc++.so.5
#10 0x07c70b68 in std::string::_Rep::_S_create() from /.../libstdc++.so.5
#11 0x081c5ec0 in std::string::_S_construct<char*>()
#12 0x081c33a2 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char*>()
#13 0x081c296e in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str()
#14 0x02af7d7a in os::bad_allocation_t::bad_allocation_t() from /.../libmylib.so
#15 0x02af84a9 in operator new() from /.../libmylib.so
#16 0x07c6b0f1 in std::__default_alloc_template<true, 0>::_S_chunk_alloc() from /.../libstdc++.so.5
#17 0x07c6affd in std::__default_alloc_template<true, 0>::_S_refill() from /.../libstdc++.so.5
#18 0x07c6ab6c in std::__default_alloc_template<true, 0>::allocate() from /.../libstdc++.so.5
#19 0x07c78b2f in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create() from /.../libstdc++.so.5
#20 0x07c78c59 in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone() from /.../libstdc++.so.5
#21 0x07c76996 in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve() from /.../libstdc++.so.5
#22 0x07c76cff in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::append() from /.../libstdc++.so.5
在#14你看bad_alloc的包裹在自己的異常類被抓,然後創建另一個字符串。
在#15你看到了自己的運營商新的這只是調用的std :: malloc的,檢查它的回報,並引發bad_allocation_t當空
而其他線程:
#0 0x004cf7a2 in _dl_sysinfo_int80() from /lib/ld-linux.so.2
#1 0x034ba3de in __lll_mutex_lock_wait() from /lib/tls/libpthread.so.0
#2 0x034b700b in _L_mutex_lock_35() from /lib/tls/libpthread.so.0
#3 0x18f54584 in ??()
#4 0x07c9f9bc in ??() from /.../libstdc++.so.5
#5 0x00000033 in ??()
#6 0x07ca1714 in std::__default_alloc_template<true, 0>::_S_free_list() from /.../libstdc++.so.5
#7 0x9b4236c8 in ??()
#8 0x07c6ab7e in std::__default_alloc_template<true, 0>::allocate() from /.../libstdc++.so.5
#9 0x07c6ab7e in std::__default_alloc_template<true, 0>::allocate() from /.../libstdc++.so.5
#10 0x07c78b2f in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_create() from /.../libstdc++.so.5
#11 0x07c78c59 in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_M_clone() from /.../libstdc++.so.5
#12 0x07c76996 in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::reserve() from /.../libstdc++.so.5
#13 0x07c76cff in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::append() from /.../libstdc++.so.5
任何人都可以提供比任何更深入的瞭解我到目前爲止收集到了什麼?
在gcc 3.3.3中(看來在這個版本之後,STL分配器有一些變化),在__default_alloc_template中確實存在一些導致死鎖的鎖定。 – 2010-09-02 13:20:25