detect non reentrant function

Discussion in 'C Programming' started by SHP, Apr 8, 2008.

  1. SHP

    SHP Guest

    Hi
    It there a way to detect non reentrant or thread unsafe function
    usage at compile time? Any option in gcc?

    thanks
    shekhar
    SHP, Apr 8, 2008
    #1
    1. Advertising

  2. On 8 Apr 2008 at 21:59, SHP wrote:
    > Hi
    > It there a way to detect non reentrant or thread unsafe function
    > usage at compile time? Any option in gcc?


    The compiler might be able to prove that some functions are thread-safe:
    for example, it can know that a function is pure if it doesn't reference
    static or global variables (only automatic variables, which are kept
    within its stack frame), doesn't use pointers, and only uses pure
    standard library functions.

    Similarly, it can know that some functions are thread-unsafe: for
    example, a function that modifies a global variable without first
    locking a mutex.

    But for most functions, it will be completely impossible for the
    compiler to know whether they are thread-safe or not. As soon as a
    function calls another function that's defined in some external library
    (which may not even be written in C, even if the source code is
    available), what possible hope is there for the compiler to decide
    whether it's thread-safe?

    I don't know how sophisticated static analysis tools have become in
    trying to decide thread-safety, if that's your question, but they
    certainly can't always succeed.
    Antoninus Twink, Apr 8, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hanspeter Moessenboeck

    Compiler generator Coco/R: Reentrant version

    Hanspeter Moessenboeck, Apr 27, 2005, in forum: Java
    Replies:
    0
    Views:
    494
    Hanspeter Moessenboeck
    Apr 27, 2005
  2. junky_fellow

    reentrant functions

    junky_fellow, Oct 30, 2004, in forum: C Programming
    Replies:
    6
    Views:
    455
    Steve Graegert
    Oct 31, 2004
  3. TheOne

    List of reentrant C library functions

    TheOne, Nov 28, 2005, in forum: C Programming
    Replies:
    9
    Views:
    621
    P.J. Plauger
    Nov 29, 2005
  4. TheOne
    Replies:
    2
    Views:
    1,141
    Maxim Yegorushkin
    Nov 24, 2005
  5. Bob from Chesham Bois

    Can using "register" make code non-reentrant?

    Bob from Chesham Bois, Jul 20, 2009, in forum: C++
    Replies:
    3
    Views:
    399
    Richard Herring
    Jul 20, 2009
Loading...

Share This Page