Re: Reentrancy
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Thu, 09 Apr 2009 17:41:15 -0500
On Thu, 9 Apr 2009 17:22:09 -0500, "Ben Voigt [C++ MVP]"
<rbv@xxxxxxxxxxxxx> wrote:
Also, different environments may have synchronous or asynchronous signal
handling. With synchronous signal handling, like on Windows, only functions
that call user-defined callbacks have to be designed for re-entrancy. With
asynchronous signal handling, like Unix, a signal can arrive at anytime and
a signal handler can start executing almost anywhere, so even if your
function does not call any callbacks, it still needs to be concerned with
re-entrancy. asctime is a classic example -- it is not re-entrant, but on
Windows this is never a problem, because there's no way to re-enter it. On
Unix, you'd better avoid calling asctime from inside a signal handler
because it might have been running when the signal arrived.
Of course, your callback/signal handler has to also not make assumptions
about the state of global variables... who knows what piece of code was
running when the signal came in. Doing any operation on a global variable
from inside a callback or signal handler needs to be done with extreme care,
whether it is passing its address to a function or even just incrementing,
it could mess up functions further down the call stack. Especially in an
environment with asynchronous signal handling, where the suspended code has
absolutely no way to know when/where it will be interrupted.
Funny, I had written "Signal handlers are somewhere in between," but I
deleted it as that seemed a little too glib, and I didn't feel like
expanding on it. So thanks for writing that. Also, driver programmers would
no doubt talk about interrupt handlers, APCs, etc.
--
Doug Harrison
Visual C++ MVP
.
- References:
- Reentrancy
- From: Kürşat
- Re: Reentrancy
- From: Doug Harrison [MVP]
- Re: Reentrancy
- From: Kürsat
- Re: Reentrancy
- From: Doug Harrison [MVP]
- Re: Reentrancy
- From: Ben Voigt [C++ MVP]
- Reentrancy
- Prev by Date: Re: Directory list box in Visual C++
- Next by Date: Re: where has linker got list of libraries from in command line?
- Previous by thread: Re: Reentrancy
- Next by thread: Re: Reentrancy
- Index(es):
Relevant Pages
|