How to stop a thread if i only have a reference to the object that was used to create the thread (the object that was passed to the Thread constructor) but not to the thread itself?
Asked
Active
Viewed 131 times
1 Answers
1
You could include an atomic boolean flag in that object that is passed to the constructor, and poll it from the thread. If the shutdown flag is set, the thread can shut down.
That can be describe as a cooperative shutdown protocol.

Philipp Claßen
- 41,306
- 31
- 146
- 239