2
スレッドが特定のスコープ内にあるときにスレッドの中断を防止しようとしています。ただし、boost::this_thread::disable_interruption di()
を使用しても影響はありません。boost disable_interruption thread_interruptedを防止しない
#include <boost/thread.hpp>
#include <iostream>
void worker() {
std::cout << "START" << std::endl;
for(;;) {
{
boost::this_thread::disable_interruption di();
try {
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
catch(boost::thread_interrupted & e) {
assert(false);
}
}
try {
boost::this_thread::interruption_point();
}
catch(boost::thread_interrupted & e) {
break;
}
}
std::cout << "END" << std::endl;
}
int main() {
boost::thread thread(&worker);
thread.interrupt();
thread.join();
}
ドキュメントはdi
がスコープ内にある間、boost::this_thread::sleep()
はboost::thread_interrupted
を投げないであろうことを意味すると思われます。
私は間違っていますか?
ありがとう、これで問題は解決しました。しかし、それがどのように機能を宣言しているのか説明できますか? 'disable_interruption'はタイプです。 – Timesquare
@ティムスクエア:それは興味深い問題です。あなたはそれについて読むことができます[ここ](http://stackoverflow.com/questions/1034606/is-there-any-use-for-local-function-declarations)。 –
最も厄介な構文解析:) – Kratz