Hello everyone, hope you are having a great day.
I want to make one of my blocking methods into a non-blocking one. i.e making it asynchronous if you will.
If I simply do something like
Code:
std::thread t(&MyClass::MyMethod, myobj);
t.detach();
will I be able to interact with this now detached thread? I mean suppose in my method (that I'm running as a second thread) I have a while loop like this :
Code:
while (this->IsRunning())
{
//lots of stuff
}
Will I still be able to do
Code:
this->SetRunning(false)
from my main thread and thus end the while loop (therefore ending the child thread execution and thus freeing the memory allocated in that child thread) ?
If detaching the child thread ends all ties with the parent, how should I be doing this then?
To give you a better idea what I'm after, here how it goes:
Basically what I'm trying to do is that I want to create a class that runs a child thread which sits and listens/does something until something of intreset happens/is found, then it fires a callback.
the client would simply create an instance of my class, add some callback handlers and then calls and goes to do whatever else he/she wants to do.
the thread will fire whenever something comes up and clients code gets run. user can also shutdown the processing by doing forexample which essentially sets that while loop to end.
How should I go about this?
Thank you all in advance