title: Difference between pthread_exit(PTHREAD_CANCELED) and pthread_cancel(pthread_self())
body: <p>When <code>pthread_exit(PTHREAD_CANCELED)</code> is called I have expected behavior (stack unwinding, destructors calls) but the call to <code>pthread_cancel(pthread_self())</code> just terminated the thread.</p>
  <p>Why <code>pthread_exit(PTHREAD_CANCELED)</code> and <code>pthread_cancel(pthread_self())</code> differ significantly and the thread memory is not released in the later case?</p>
  <p>The background is as follows:</p>
  <p>The calls are made from a signal handler and reasoning behind this strange approach is to cancel a thread waiting for the external library <code>semop()</code> to complete (looping around on <code>EINTR</code> I suppose)</p>
  <p>I have noticed that calling <code>pthread_cancel</code> from other thread does not work (as if <code>semop</code> was not a cancellation point) but signalling the thread and then calling <code>pthread_exit</code> works but calls the destructor within a signal handler.
  <code>pthread_cancel</code> could postpone the action to the next cancellation point.</p>