<p dir="ltr"></p>
<p dir="ltr">On Sep 27, 2016 15:00, "Eric S. Raymond" <<a href="mailto:esr@thyrsus.com">esr@thyrsus.com</a>> wrote:<br>
><br>
> Hal Murray <<a href="mailto:hmurray@megapathdsl.net">hmurray@megapathdsl.net</a>>:<br>
> > man 7 signal has a long list of what you can do in a signal handler.  (all<br>
> > other system calls are unsafe)<br>
> ><br>
> > Is there something similar that applies to killing threads?  If so, where is<br>
> > it documented?<br>
> ><br>
> > For example, if I kill a thread that is in the middle of malloc, are things<br>
> > guaranteed to work correctly or can some global state be left in a broken<br>
> > condition.  (or a lock locked, or ...)<br>
><br>
> It varies.  Some library calls are documented to be thread-safe.  The glibc<br>
> version of malloc is; some older versions were not.  In general, if it's<br>
> not documented thread-safe you need to wrap your own mutex around it.</p>
<p dir="ltr">Hal's question was about *killing* threads. Even if a thread only 3<br>
ever makes thread-safe calls, it's still unsafe to kill, because doing so can leave its mutexes locked and the data they control in an inconsistent state. <br>
</p>