Closed Bug 198634 Opened 21 years ago Closed 21 years ago

Fixes to OS/2 threading code

Categories

(NSPR :: NSPR, defect, P1)

x86
OS/2
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mkaply, Assigned: wtc)

Details

Attachments

(2 files, 1 obsolete file)

We're getting asserts in our threading code which is causing the new NSS utility
not to work (shlibsign)

Fix coming.
Attached patch Fix for problemSplinter Review
Comment on attachment 118047 [details] [diff] [review]
Fix for problem

r=mkaply - this patch was from Javier
Attachment #118047 - Flags: review+
Attachment #118047 - Flags: superreview+
Patch checked into the NSPR TIP (4.3) and NSPRPUB_PRE_4_2_CLIENT_BRANCH
(mozilla 1.4alpha).

Is this for the assertion failure in PR_Cleanup()?  I seem to recall
you opened a bug about that but can't find it.  Maybe you told me about
it in email.
Status: NEW → RESOLVED
Closed: 21 years ago
Priority: -- → P1
Resolution: --- → FIXED
Target Milestone: --- → 4.3
Question: shouldn't you implement PR_DetachThread too for OS2? 
_PRI_DeatchThread()/PR_DeatchThread isn't called if an attached thread exits
outside mozilla.
Meaning, NSPR on Win32 will catch this case in the DllMain() of NSPR, OS/2
won't. So, the result will be some leaked PRThread structs and a wrong thread
count (_pr_userActive).
Patch Suggestion:

PR_IMPLEMENT(void) PR_DetachThread(void)
{
#ifdef XP_OS2
    if (_pr_initialized) {
        me = _MD_GET_ATTACHED_THREAD();
        if ((me != NULL) && (me->flags & _PR_ATTACHED))
            _PRI_DetachThread();
    }
#endif
}
When would PR_DetachThread ever get called?

Would we expect outside users of NSPR threads to do this?
Except for the testcase mozilla\nsprpub\pr\tests\attach.c no-one calls it. 
Guessing the intended usage was to call this before exiting a user thread
previously attached with PR_AttachThread(). Like we do from our private
DLL_THREAD_DETACH handler. 
Or if you like, you can export _PRI_DetachThread let me countinue call it, as
I'm doing now.
I'd rather give you PR_DetachThread.

So it's mainly for externals to use. That's cool.

I'll put this in the NSPR I give you Monday.

In the current version of NSPR, PR_DetachThread is a no-op.
It is only there for backward compatibility purposes.

What PR_DetechThread used to do should now be done by a
handler that is called on thread termination.  On Unix,
this is done as a thread-specific data destructor.  On
Win32, this is done as DLL_THREAD_DETACH code in DllMain().
Does OS/2 have something that you can use for this purpose?
As I pointed out in my first comment, no. That's why I need it.
I see.  I asked because you mentioned your "DLL_THREAD_DETACH handler"
in comment 6.  Can we add a DLL_THREAD_DETACH handler to NSPR?
Sorry, about the confusion. I've a habit of forgetting to assert the context in
which I'm writing. We're 'porting' (wrapping are perhaps a better term as we
don't change the binary) a Win32 plugin to OS/2, and I was refering to our
_private_ DLL_THREAD_DETACH.
To be very clear.

OS/2 has NO way to detect thread death.

We MUST have a PR_DetachThread for OS/2 and expect people to call it.

Patch coming.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Thanks.
OK, here is an implementation of PR_DetachThread.

I deliberately did not make it XP_OS2. There should be a PR_DetachThread that
can be called if necessary. You can't always rely on platform specific
behaviors to detach threads.
This should probably be ifdef'ed with

  #if !defined(WIN32)

because Win32 threads are detached in the DllMain()
function of nspr4.dll.

Mike, I think your patch is correct; it's just that
I need to think about it more to be sure that no code
can possibly depend on the current behavior.  So adding
the ifdef is safer.
Then lets just #ifdef XP_OS2 this so we can get it in.

Thanks
Please try this patch.	Thanks.
Attachment #118697 - Attachment is obsolete: true
Comment on attachment 119883 [details] [diff] [review]
Proper implementation of PR_DetachThread v1.1

This looks good to me.
Attachment #119883 - Flags: review+
I checked in the PR_DetachThread patch on the
NSPRPUB_PRE_4_2_CLIENT_BRANCH (mozilla 1.4 beta)
last night.
Status: REOPENED → RESOLVED
Closed: 21 years ago21 years ago
Resolution: --- → FIXED
Whiteboard: [4.3.1]
I checked in the PR_DetachThread patch on the
NSPR trunk.
Whiteboard: [4.3.1]
Target Milestone: 4.3 → 4.4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: