Quote Originally Posted by Salem View Post
What is the scope and lifetime of myobj ?

If you're doing this
Code:
MyClass *obj = new MyClass;
std::thread t(&MyClass::MyMethod, myobj);
and MyMethod has the ability to do say delete this; as final act of suicide, then calling this->SetRunning(false) in any other thread is exceedingly risky.


But if myobj always outlives the thread instance of MyMethod, then calling SetRunning only really has to worry about concurrent access to whatever instance variable is being updated inside the object.
Atomic operations library - cppreference.com

Thanks a lot really appreciateit. yes the myobj outlives the detached thread as the user needs to have it to be able to end the `MyMethod()` thats run in a child thread.
Also I found a very intresting article which may be of use to other people like me : Asynchronous Programming — Part 1 | by Maharajan Shunmuga Sundaram | Medium