nspr based lib (solaris native thread) in single threaded application makes it MT

Assigned to


14 years ago
12 years ago


(Reporter: gerard.roos, Assigned: wtc)


Firefox Tracking Flags

(Not tracked)



(1 attachment)



14 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113
Build Identifier: 

A library built with NSPR on Solaris is multi-threaded only, i.e. such a library
turns any single-threaded application into a multi-threaded one.

Reproducible: Always
Steps to Reproduce:
Build a library with NSRP and load it into a single-threaded application.
Actual Results:  
The ST application becomes MT.

Expected Results:  
Application remains ST.

The behaviour was detected on Solaris, using NSPR, patched with patches from
#214411 (Solaris native thread support), and built with Solaris native thread

Comment 1

14 years ago
Created attachment 154973 [details] [diff] [review]
remove explicit thread linkage

'-lthread' or '-lpthread' must be removed. Explicit thread library linkage must
be done by the application. It's sufficient to make the library MT aware ('-mt'

Comment 2

14 years ago
Additionally (note that we had the patches from bug id #214411 applied),
_PRI_AttachThread in() _pr_current_thread_tls() must be given the type
PR_SYSTEM_THREAD and the flag _PR_PRIMORDIAL. Latter is necessary for assertion
in PR_Cleanup(). Former is necessary for "_pr_userActive >
_pr_primordialExitCount" in PR_Cleanup() not to wait forever.

I just point out the two affected lines (proposing further patches for NSPR 4.3
(which we are using) makes not much sense here, as the affected files have
already been modified by applying the patches from #214411). But since the
modifications are simple, a glance at the code should make things clear (and the
changes probably also fit into head of NSPR well):

1) mozilla/nsprpub/pr/src/md/unix/solaris.c (in _pr_current_thread_tls(),
pass _PR_PRIMORDIAL flag to _PRI_AttachThread):

thread = _PRI_AttachThread(

2) mozilla/nsprpub/pr/src/threads/combined/pruthr.c (in _PRI_DetachThread(void),
ignore if _PR_PRIMORDIAL):

void _PRI_DetachThread(void)
    PRThread *me = _PR_MD_CURRENT_THREAD();

	if ((me->flags & _PR_PRIMORDIAL) && !(me->flags & _PR_ATTACHED)) {
		 * ignore, if primordial thread

Comment 3

14 years ago
hmm, one thing I forgot to add:
On Solaris 2.6 (SunOS 5.6) using native solaris threads, if a library links nspr
statically, and that library calls thr_create directly or indirectly (e.g. the
call happens in NSPR), the lib itself must be linked with '-lthread', otherwise
thr_create returns -1.
On Solaris 2.8 (SunOS 5.8) this is not an issue (the lib is not required to be
linked with '-lthread').
QA Contact: wtchang → nspr
You need to log in before you can comment on or make changes to this bug.