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

查看:118
本文介绍了是否有可能的方法映射信号处理(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.

您应该做的是在信号处理程序中设置一个标志,定期检查您的代码,并在检测到标志设置时抛出异常。

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.

这种方法类似于 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天全站免登陆