Bug 163512 - libc defaults to single threaded
Summary: libc defaults to single threaded
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: 1.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-threads (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-21 19:10 UTC by Steve Wills
Modified: 2017-02-27 19:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Wills freebsd_committer freebsd_triage 2011-12-21 19:10:09 UTC
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

Fix: 

I'm told merging libthr into libc may help, but I'm not really sure. No ideas beyond that.
How-To-Repeat: 1. update ports tree
2. Ensure perl is not build with threads (currently not building with threads is the default)
2. cd /usr/ports/devel/p5-Glib2
3. rm files/patch-threadstest
4. make
5. cd work/Glib-1.241
6. make test
7. Verify perl is hung trying to run t/9.t
Comment 1 Daniel Eischen freebsd_committer freebsd_triage 2011-12-21 19:28:58 UTC
>> 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
Comment 2 Steve Wills freebsd_committer freebsd_triage 2015-01-18 16:57:19 UTC
This needs to be retested after r277032 which may have fixed the issue.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2015-05-14 21:21:11 UTC
Yes, this is now expected to be fixed.
Comment 4 Steve Wills freebsd_committer freebsd_triage 2017-02-27 19:03:41 UTC
Closing, fixed.