What you might want is an interrupting thread, c++ doesn't give you one but c++ concurrency in action has a simple implementation of one. That might be what you need. Wouldn't be surprised if boost also has one since the book is written by the maintainer of the thread library.
class interrupt_flag
{
public:
void set();
bool is_set() const;
};
thread_local interrupt_flag this_thread_interrupt_flag;
class interruptible_thread
{
std::thread internal_thread;
interrupt_flag* flag;
public:
template<typename FunctionType>
interruptible_thread(FunctionType f)
{
std::promise<interrupt_flag*> p;
internal_thread=std::thread([f,&p]{
 p.set_value(&this_thread_interrupt_flag);
f();
});
flag=p.get_future().get();
}
void interrupt()
{
if(flag) {
flag->set();
}
}
};
Now you can easily cancel the thread from your main. I put a link to the book but all the code from the book is also online for free. Here is a link to the source code in the book, though it may be hard to navigate without the book, which is a great read BTW.
>>? An asychronous io call might help (if not standardized).>>but I've found something: when I detach the thread in the constructor of the ThreadClass I wrote, i've problems; when I detach it in the mainloop, it works randomly: if the thread starts to be executed before beeing detached, it doesn't work, in the other case it works.