是否有映射信号处理(C库)到C ++异常可能的方法? [英] Are there possible approaches to map signal handling (c library) into a c++ exception?

查看:266
本文介绍了是否有映射信号处理(C库)到C ++异常可能的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一些C库链接的C ++应用程序。

I have a c++ application linked against some c libraries.

在那里封装在C ++类处理信号可能的方法,因此它可以作为一个C ++异常处理?

Are there possible approaches to encapsulate the signal handling in a C++ class, so it could be handled as a c++ exception?

推荐答案

您不能及,如果你可以有很多东西会打破。

You can't and if you could a lot of things would break.

你应该做的是设置在信号处理程序中一个标志,定期检查你的code,当你检测标志设置抛出异常。

What you should do is set a flag in the signal handler, periodically check in your code and throw an exception when you detect the flag is set.

这种方法类似于线程获得如何<一个中断href=\"http://www.boost.org/doc/libs/1_40_0/doc/html/thread/thread_management.html#thread.thread_management.interruption\"相对=nofollow> Boost.Threads 中,我强烈建议你学习。

Such an approach is similar to how threads get interrupted in Boost.Threads, which I strongly suggest you study.

这篇关于是否有映射信号处理(C库)到C ++异常可能的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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