Say I am a utility routine; I might have been called from a signal handler or from 'normal' (possibly multithreaded) code.
Now if I want to print some debug-message, I should use printf/fprintf as they are thread-friendly.
But if I was called from a signal-handler, I should call sprintf+write.
Now is there a way to find this out programatically?
Note: this question was motivated by this: How can I debug runtime library interpositioned process?
Edit: let me summarize the problem this way: a routine wants to write a debug-message, is it supposed to use high-level-IO (FILE
) or low-level-IO (write
)? High-level is thread-friendly, but not to be used in signal-handler; low-level is the opposite: usable in signal-handler, but not thread-friendly.