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

Cancellation is just an exception, so destructors work automatically. Any implementation of a language that uses RAII without integrating cancellation into it is fundamentally broken and should be avoided at all costs. `pthread_cleanup_push` (or `__attribute__((cleanup))` is only needed if you're implementing it by hand.

Since the set of functions that can be cancelled is documented (and pretty obvious - roughly, any blocking function but notably excluding mutex functions), there's no "unknown" involved. At most there is "I insisted on writing C but refused to take the effort to make my code correct in a threaded environment."

Notably, `malloc` is not a cancellation point so this all is much easier to deal with than signals.



> Cancellation is just an exception

It's not guaranteed to be implemented that way, and even if it was, not all kind of unwinds are compatible.




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

Search: