Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



So 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.


If 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: