Bug 4475 - configure checks pthread.h but not pthread library
Summary: configure checks pthread.h but not pthread library
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.0.0
Hardware: All All
: high normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
: 4679 6864 7744 9082 (view as bug list)
Depends on:
Blocks: 7141
  Show dependency treegraph
 
Reported: 2005-09-16 08:41 UTC by Tim Mooney
Modified: 2012-02-10 11:45 UTC (History)
5 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Tim Mooney 2005-09-16 08:41:48 UTC
cairo 1.0.0's configure checks are incomplete: it checks for pthread.h and
defines HAVE_PTHREAD if it finds it, but it never checks to see if it needs any
additional libraries for pthread_mutex_lock() and pthread_mutex_unlock().

This causes problems on several UNIX platforms that have pthread routines in a
separate library, such as libpthread.

The way to fix this is to borrow the pthread library checks from some other
package that's GPL and uses autoconf -- robust support of pthreads isn't as
simple as just adding an AC_CHECK_LIB or AC_CHECK_FUNC, because of some of the
header file chicanery used for symbol mapping on some platforms.

I can look around for a good candidate package if you like.
Comment 1 Behdad Esfahbod 2006-06-13 23:28:13 UTC
Tim, please go ahead with your pthread autoconf shopping.
Comment 2 Behdad Esfahbod 2006-06-13 23:38:42 UTC
*** Bug 6864 has been marked as a duplicate of this bug. ***
Comment 3 Behdad Esfahbod 2006-06-13 23:39:03 UTC
*** Bug 4679 has been marked as a duplicate of this bug. ***
Comment 4 Tim Mooney 2006-06-14 08:17:39 UTC
Ok, will do, though it's going to be harder for me to test right now than it
would have been last year -- I don't have convenient access to OSF1 / Tru64 UNIX
right now, and that's one of the platforms that exhibit this problem.

I'll start looking for good pthread checks in GNOME packages, and update this
bug this weekend.
Comment 5 Tim Mooney 2006-06-28 16:12:36 UTC
I spent a little time looking, and glib has a lengthy set of checks to find the
necessary flags and libraries for thread support.  Those checks might be
overkill for cairo, but they're certainly well-tested and robust.

I'm looking at glib-2.10.2/configure.in starting with

  g_thread checks

and continuing all the way down to

  AC_MSG_CHECKING(thread related libraries)

Those checks could be incorporated into cairo with some work (they could
probably be pared down a bit).

This brings up a question, though.  glib supports more threading models than
just POSIX threads.  Would it make any sense to (some day) have cairo use
gthreads instead of using POSIX threads directly?
Comment 6 Chris Wilson 2008-10-10 13:58:23 UTC
*** Bug 7744 has been marked as a duplicate of this bug. ***
Comment 7 Chris Wilson 2008-10-10 13:59:10 UTC
*** Bug 9082 has been marked as a duplicate of this bug. ***
Comment 8 Chris Wilson 2008-10-10 14:00:55 UTC
Just a reminder: the configure check also needs to discover how to correctly link to pthread.
Comment 9 Behdad Esfahbod 2009-08-31 14:16:43 UTC
My current understanding is that:

1) Header check is needed, obviously, since we include it.

2) We don't want to link to pthread.  Not on Linux.

3) We do want to make sure we can link a test program using pthread symbols.  On Linux, glibc provides weak version of those symbols.

If 3 fails, most probably we don't want pthread, since it most probably means there are native mutexes available.  We may want to make --enable-pthread=yes try -lpthread if 3 fails.
Comment 10 Paolo Borelli 2009-08-31 14:23:39 UTC
Apart from detection, I think configure should also be tweaked to have a proper default value, so that eg on windows pthread is not even tested unless one really knows what he is doing and specifies --enable-pthread.


# by default disable pthreads on platforms with native threads
AC_ARG_ENABLE(pthread,
  AS_HELP_STRING([--disable-pthread],
		 [Do not use pthread]),
  [use_pthread=$enableval],
  [case "$host" in
    *-*-mingw*)
      use_pthread=no
      ;;
    *-*-beos)
      use_pthread=no
      ;;
    *-*-os2)
      use_pthread=no
      ;;
    *)
      use_pthread=auto
      ;;
    esac
  ])
Comment 11 Chris Wilson 2009-12-02 10:30:16 UTC
As an extra complication we only want pthread-stubs for the library, but may want to use a real pthreads for multi-threaded testing.
Comment 12 Behdad Esfahbod 2009-12-02 10:53:15 UTC
gmodule is moving towards linking to pthreads by default.  Maybe we can do the same....
Comment 13 Uli Schlachter 2012-02-10 11:45:24 UTC
The header-only pthread check was already removed two years ago:

commit e3b2212bc5c4884eab356ae263b8318e10c379ac
Author: Benjamin Otte <otte@redhat.com>
Date:   Thu May 13 15:14:29 2010 +0200

    build: Fix pthread detection
    
    Incorporate the pthread detection code from the autoconf archive. Should
    fix build on obscure archs that pretend to be UNIXy - like Mac OS X
    Tiger.
    
    http://www.gnu.org/software/autoconf-archive/
    http://www.gnu.org/software/autoconf-archive/ax_pthread.html

Later on, that was improved again:

commit fca8977219b857e2e61dd86ac39ae9f40086f306
Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
Date:   Sun Jun 27 03:03:17 2010 +0300

    build: Rework pthread detection.
    
    Use two levels of pthread support: a minimal level used to
    build cairo itself, and a full level to build threaded apps
    which want to use cairo.  The minimal level tries to use
    pthread stubs from libc if possible, but falls back to the
    full level if that's not possible.  We use CFLAGS=-D_REENTRANT
    LIBS=-lpthread to find a real pthread library since that seems
    to work on every unix-like test box we can get our hands on.

This should be more than enough to consider this bug fixed.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.