C ++线程异常问题 [英] C++ thread exceptions problem

查看:135
本文介绍了C ++线程异常问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不同的线程中同时捕获大量异常时遇到问题:负载平均值指标超过100.0并且该过程似乎挂断。

我设法模拟了这种情况,创建了一个测试程序,其中包含大约200个线程,每个线程包含一个抛出并捕获异常的FINITE循环。例外不会留下线程功能。测试开始工作,并在某个时刻阻止。在某些其他条件下,测试可以完成(当线程数较低或者抛出异常之间的间隔较大时)。它甚至可以通过相同的条件,因此它的行为是不可预测的。

我在使用FreeBSD7.0的2核amd64上使用boost :: thread over libpthread和g ++ 4.2.1。有趣的是,在Linux下,这个测试运行顺利。


当测试应用程序挂起时,我用-11信号杀死它,这就是我在gdb中看到的:

(gdb)其中

#0 0x0000000801554636 in __fixunssfti()from /lib/libgcc_s.so.1

]#1 0x00000008005c6343 in dl_iterate_phdr()from /libexec/ld-elf.so.1

#2 0x0000000801554bdf in _Unwind_Find_FDE()from /lib/libgcc_s.so.1

#3 0x0000000801551525 in _Unwind_GetIPInfo()from /lib/libgcc_s.so.1

#4 0x000000080155296e in_Unwind_RaiseException()from /lib/libgcc_s.so.1

#5 0x00000008012a2abd in __cxa_throw()from / usr /lib/libstdc++.so.6

.....


当我的实际应用程序挂起异常时,它也一样。

I have a problem when catching a plenty of exceptions simultaneously in different threads: the Load Average indicator exceeds 100.0 and the process seems to "hang up".
I managed to simulate this situation having created a test program with a number of threads about 200 each containing a FINITE loop with throwing and catching an exception. The exceptions don''t leave thread function. The test starts to work and at some moment blocks. Under some other conditions the test may finish (when number of threads is lower or when intervals between throwing exceptions are bigger). It can pass even with the same conditions, so it''s behavior is unpredictable.
I use boost::thread over libpthread and g++ 4.2.1 on 2-core amd64 with FreeBSD7.0. It''s interesting that under Linux this test runs smoothly.

when the test application hangs, I kill it with -11 signal and that is what I see in gdb:
(gdb) where
#0 0x0000000801554636 in __fixunssfti () from /lib/libgcc_s.so.1
]#1 0x00000008005c6343 in dl_iterate_phdr () from /libexec/ld-elf.so.1
#2 0x0000000801554bdf in _Unwind_Find_FDE () from /lib/libgcc_s.so.1
#3 0x0000000801551525 in _Unwind_GetIPInfo () from /lib/libgcc_s.so.1
#4 0x000000080155296e in _Unwind_RaiseException () from /lib/libgcc_s.so.1
#5 0x00000008012a2abd in __cxa_throw () from /usr/lib/libstdc++.so.6
.....

The same is in my real application when it hangs on exceptions.

推荐答案

可能这是一个死锁,其中一个线程正在等待另一个线程拥有的资源。


你如何处理锁定通信使用资源?
Probably this is a deadlock where more then one thread is waiting on a resource owned by the other thread.

How are you handling locking where common resources are used?



可能这是一个死锁,其中有多个线程正在等待另一个线程拥有的资源。 br />

如何处理使用公共资源的锁定?
Probably this is a deadlock where more then one thread is waiting on a resource owned by the other thread.

How are you handling locking where common resources are used?



好​​吧,测试代码似乎没有使用任何共享资源。这是测试线程例程:

well, test code doesn''t seem to utilize any shared resource. Here is test thread routine:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号


没有人遇到过这个问题?嘿,大师,试试这个测试用例,这并不难做到! :)你可以用std :: exception替换ExceptionBase,结果对我来说类似。如果图书馆出现问题 - 应该揭开它,或者我可能做错了什么?请帮助我,因为这个问题长期困扰生产系统的工作!
Hadn''t nobody faced the problem? Hey, gurus, try this test case, it''s not so hard to do! :) You can replace the ExceptionBase with std::exception, the result was similar for me. If there is a problem in libraries - it should be uncovered, or may be I do something incorrect? Please, help me, for the problem disturbs working of production system for the long period!


这篇关于C ++线程异常问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆