[Top][All Lists]

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

Re: multithread modules

From: Bruno Haible
Subject: Re: multithread modules
Date: Thu, 6 Mar 2008 14:10:50 +0100
User-agent: KMail/1.5.4

Simon Josefsson wrote:
> Hm.  lock.m4 contains:
>     # For using <pthread.h>:
>     case "$host_os" in
>       osf*)
>         # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
>         # groks <pthread.h>. cc also understands the flag -pthread, but
>         # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
>         # 2. putting a flag into CPPFLAGS that has an effect on the linker
>         # causes the AC_TRY_LINK test below to succeed unexpectedly,
>         # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
>         ;;
>     esac
> This seems to imply that if I don't use pthread.h, I won't find
> -D_REENTRANT useful

No, that's not implied by the above statement. The above statement only
says that

  #undef _REENTRANT
  #include <pthread.h>

will lead to an error on OSF/1.

> except for possibly the next statement:
>     # Some systems optimize for single-threaded programs by default, and
>     # need special flags to disable these optimizations. For example, the
>     # definition of 'errno' in <errno.h>.
>     case "$host_os" in
>       aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
>       solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
>     esac
> Do you know any operating system manuals that document this?  I'm trying
> to understand precisely when I need to use any of these flags.
> Generally, if some systems need -D_REENTRANT to get a usable errno,

The above list of platforms was indeed compiled by looking for a multithread-
aware errno.

> wouldn't that be something we could write a gnulib module for?

I can see three levels of multithreading support that you might ask for:
  1) just turn on multithreading, and 'errno',
  2) also use locks,
  3) also use primitives that create and control threads.

#2 is what the 'lock' module currently implements.

#1 is not a practical use-case for me, since at some point one needs global
variables and therefore locks. But if it is useful for you, we can split off
part of the 'lock' module into a module that does just #1.

#3 is pretty easy (module 'lock' and a test for LIBSCHED). I prefer to use
OpenMP instead, when possible.


reply via email to

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