threads/163512: libc defaults to single threaded

Daniel Eischen deischen at freebsd.org
Wed Dec 21 19:29:00 UTC 2011


>> Description:
> 1) libc defaults to being single-threaded
> 2) thus apps not linked against libthr don't initialize the structures that threading depends on
> 3) this causes bugs when said app loads a library that loads libthr
> 4) said library will take the threaded code path and reference uninitialized data structures
>
> An example of this can be seen by removing ports/devel/p5-Glib2/files/patch-threadstest then after building, run "make test" from work/Glib-1.241. Perl will hang in state umtxn.
>
> I believe this may also be the source of an intermittent hang in automoc4 (also stuck in state umtxn) seen while building x11/kde4. This was discussed here:
>
> http://mail.kde.org/pipermail/kde-freebsd/2011-November/012211.html
> https://bugs.kde.org/show_bug.cgi?id=276461

This has always been the case.  If an application is going to be
linked to a library that requires threads, then that application
has to link to libpthread.  Applications should be built knowing
whether libpthread will be required or not.  Either that, or
the library should be built to detect whether threading is
present and only use thrading features when threading is
present (see how libgcc does this as example).  The former or
latter depends on the what the library is trying to provide.
If it needs to spawn threads to accomplish its job, then
the former (application needs to link with libpthread).  If
the library just needs synchronization primitives to protect
against a threaded application, then you can use the latter.

If the application is kinda stupid and really doesn't know
if threads are required, then there probably is no harm in
always linking to libpthread.

-- 
DE


More information about the freebsd-threads mailing list