¿ 如何中断正在执行 MKL 子程序的线程?在其他 3rd 方库中?我的线程是用 boost::thread 创建的,通常我使用中断来停止我的线程(http://www.boost.org/doc/libs/1_41_0/doc/html/thread/thread_management.html#thread.thread_management.中断),但我怎样才能停止执行 MKL 代码的线程呢?有任何想法吗?
提前致谢
¿ 如何中断正在执行 MKL 子程序的线程?在其他 3rd 方库中?我的线程是用 boost::thread 创建的,通常我使用中断来停止我的线程(http://www.boost.org/doc/libs/1_41_0/doc/html/thread/thread_management.html#thread.thread_management.中断),但我怎样才能停止执行 MKL 代码的线程呢?有任何想法吗?
提前致谢
In a nutshell: You cannot.
Thread interruption points as used by Boost have to be used cooperatively, that is the code that is to be interrupted needs to voluntarily trigger a function call that can act as an interruption point. Since MKL does not do that, you are out of luck.
The best way to solve this is to divide your problem into small chunks that don't require long to execute and then check for interruption requests between processing of chunks.
For the sake of completeness: Some APIs allow brute-force cancellation of threads that does not require the canceled thread's permission (Boost is not one of them). However, this is quite dangerous to use as the canceled thread is usually unable to cleanup properly and may thus easily leave the program in a corrupted state. Should you decide to go down that road it is probably a better idea to use different processes instead of threads, as forcefully killing a process is much less error-prone than killing threads.