This article is from the Threads Programming FAQ, by Bryan O'Sullivan email@example.com with numerous contributions by others.
Some library routines can be safely called from within signal
handlers; these are referred to as async-safe. A thread that is
executing some async-safe code will not deadlock if it is interrupted
by a signal. If you want to make some of your own code async-safe, you
should block signals before you obtain any locks.