[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble: GTK + Octave + PThreads

From: Rafael Laboissiere
Subject: Re: Trouble: GTK + Octave + PThreads
Date: Thu, 5 Nov 1998 17:17:32 +0100 (MET)

>>>>> "JWE" == John W Eaton <address@hidden> writes:

    JWE> |     JWE> What does -D_REENTRANT do for complinig Octave?
    JWE> | 
    JWE> | I compiled version with -D_REENTRANT.  It works normally. 

    JWE> That doesn't answer my question.  What is the purpose of
    JWE> -D_REENTRANT?  That symbol is not used in the Octave code.
    JWE> Adding it to the compiler flags might have some effect on the
    JWE> functions declared in system header files, but I don't think it
    JWE> will make the Octave code reentrant.

Well, It will make Octave code reentrant at least partially, because
using -D_REENTRANT will force some redefinitions at the libc level.
Taken from the LinuxThreads FAQ

H.1: You say all multithreaded code must be compiled with _REENTRANT
     defined. What difference does it make?

It affects include files in three ways: 

  o The include files define prototypes for the reentrant variants of
    some of the standard library functions, e.g.  gethostbyname_r() as a
    reentrant equivalent to gethostbyname().

  o If _REENTRANT is defined, some <stdio.h> functions are no longer
    defined as macros, e.g. getc() and putc().  In a multithreaded
    program, stdio functions require additional locking, which the
    macros don't perform, so we must call functions instead.

  o More importantly, <errno.h> redefines errno when _REENTRANT is
    defined, so that errno refers to the thread-specific errno location
    rather than the global errno variable. This is achieved by the
    following #define in <errno.h>:

          #define errno (*(__errno_location()))

    which causes each reference to errno to call the __errno_location()
    function for obtaining the location where error codes are
    stored. libc provides a default definition of __errno_location()
    that always returns &errno (the address of the global errno
    variable). Thus, for programs not linked with LinuxThreads, defining
    _REENTRANT makes no difference w.r.t. errno processing. But
    LinuxThreads redefines __errno_location() to return a location in
    the thread descriptor reserved for holding the current value of
    errno for the calling thread. Thus, each thread operates on a
    different errno location.

Rafael Laboissiere

reply via email to

[Prev in Thread] Current Thread [Next in Thread]