Reentrant functions

A reentrant function is one that can be reentered while an ongoing invocation is still running. It's simpler than it sounds; check out this pseudo-code snippet:

signal_handler(sig) {     my_foo();    < ... > }my_foo(){    char mybuf[MAX];    <...>}do_the_work_mate(){    my_foo();    <...>}

Now imagine this sequence of activity:

  • The function my_foo() is invoked by the business logic function do_the_work_mate(); it operates on the local buffer mybuf

  • While this is still running, a signal is dispatched to this process

  • The signal handler code preempts whatever was executing at the moment it occurred and runs

    • It reinvokes the function my_foo()

So, there we see it: the function my_foo() is reentered. By itself, that's OK; the important ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.