3 ms·
I don't follow how threads are hard to cancel. Set some state (like a flag) that all threads have access to. In their work loop, they check this flag. If it's
by Night_Thastus 3y ago
I don't follow how threads are hard to cancel.
Set some state (like a flag) that all threads have access to.
In their work loop, they check this flag. If it's false, they return instead and the thread is joined. Done.
- ric2b 3y agoSo you make an HTTP request to some server and it takes 60 seconds to respond. Externally you set that flag 1 second into the HTTP request. Your program has to wait for 59 seconds before it finally has a chance at cancelling, even though you added a bunch of boilerplate to supposedly make cancellation possible.
- Night_Thastus 3y agoIf the server takes 60 seconds to respond, and you need responses on the order of 1 second, I'd say that is the problem - not threads.