| ▲ | AndyKelley 4 days ago | ||||||||||||||||||||||
What's crazy is that it's almost good. All they had to do was make the next syscall return ECANCELED (already a defined error code!) rather than terminating the thread. Musl has an undocumented extension that does exactly this: PTHREAD_CANCEL_MASKED passed to pthread_setcancelstate. It's great and it should be standardized. | |||||||||||||||||||||||
| ▲ | frumplestlatz 4 days ago | parent | next [-] | ||||||||||||||||||||||
That would have been fantastic. My worry is if we standardized it now, a lot of library code would be unexpectedly dealing with ECANCELED from APIs that previously were guaranteed to never fail outside of programmer error, e.g. `pthread_mutex_lock()`. Looking at some of my shipping code, there's a fair bit that triggers a runtime `assert()` if `pthread_mutex_lock()` fails, as that should never occur outside of a locking bug of my own making. | |||||||||||||||||||||||
| ▲ | gpderetta 4 days ago | parent | prev | next [-] | ||||||||||||||||||||||
You can sort of emulate that with pthread_kill and EINTR but you need to control all code that can call interruptable sys calls to correctly return without retry (or longjmp/throw from the signal handler, but then we are back in phtread_cancel territory) | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | cryptonector 4 days ago | parent | prev [-] | ||||||||||||||||||||||
`pthread_cancel()` was meant for interrupting long computations, not I/O. | |||||||||||||||||||||||