Thread model: single

Marcos_David.Dione@sophia.inria.fr Marcos_David.Dione@sophia.inria.fr
Fri Jan 15 13:44:00 GMT 2010


On Fri, January 15, 2010 5:18 am, Ian Lance Taylor wrote:
> Marcos_David.Dione@sophia.inria.fr writes:
>
>>     more particularly I want to know whether the "single" threaded gcc
>> configuration implies that C code is also less thread-safe, e.g.
>> because C header files are also sensitive to it.
>
> It depends.  On some systems, the -pthread option to gcc will #define
> the preprocessor symbol _REENTRANT.  It may be the case that on some
> systems the header files will notice that and change behaviour.  I
> don't think that is common.
>
> The -pthread option does not affect gcc's code generation.

    the only reference to _REENTRANT I found in android's libc, Bionic, is
in strtod.c, where it defines a global variable:

#ifdef _REENTRANT
 static mutex_t freelist_mutex = MUTEX_INITIALIZER;
#endif

    I found this comment in Bionic's code:

 * Requirements:
 *
 * 1. The thread safe mechanism should be lightweight so the library can
 *    be used by non-threaded applications without unreasonable overhead.
 *
 * 2. There should be no dependency on a thread engine for non-threaded
 *    applications.
 *
 * 3. There should be no dependency on any particular thread engine.
 *
 * 4. The library should be able to be compiled without support for thread
 *    safety.

    from #2 it seems that it actually doesn't matter which thread model
you use, bionic should be safe and quick.

    in any case, the single thread model is still not clear to me on what
consequences it brings for users of the compiler.

-- 
Lic. Marcos Dione
Engineer Expert - Hop Project
http://hop.inria.fr/
INRIA Sophia Antipolis - Méditerranée
Phone: +33 (0)4 92 38 79 67



More information about the Gcc-help mailing list