If I'm not wrong there is no easy way to make a c++0x thread cancellable. I'm wondering if it's legal to use GCancellable mixing it with c++0x thread.
If the answer is
No
I guess I should use glib threads or it's not so legal too?
I am not very familiar with GCancellable.
After a quick read through, it appears to be a hierarchical notification system.
If that is the case then yes you can easily mix GCancellable
with std::thread
.
There is no easy way to make a
std::thread
cancellable.
This is wrong.
There is no non-zero cost way to make all
std::thread
s cancellable.
This is correct.
The problem is providing a general solution. Notification is easy enough. The hard part is making sure the thread sees the notification. The thread may be blocked on a mutex or IO. You cannot just kill the thread. All sorts of bad can occur.
Each individual implementation is free to implement their own cancellation system tailored to you particular needs.
If you need to be interruptable from a blocking mutex, make sure you only use timed_mutexes, and that you call g_cancellable_is_cancelled
frequently enough that your thread will cancel as needed.