O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required