Add a test for PR_CallOnce
Categories
(NSPR :: NSPR, enhancement)
Tracking
(Not tracked)
People
(Reporter: KaiE, Assigned: KaiE)
Details
Attachments
(1 obsolete file)
Add a test that ensures that PR_CallOnce correctly blocks secondary threads that don't win the race to call the init function.
Assignee | ||
Comment 1•5 years ago
|
||
Assignee | ||
Comment 2•5 years ago
|
||
output:
Assignee | ||
Comment 3•5 years ago
|
||
output:
before call once in primary thread
entering init_once(), sleeping for a moment...
before call once in secondary thread
setting the_bool and leaving init_once()
after call once in primary thread
after call once in secondary thread
secondary thread found value of bool: 1
primary thread found value of bool: 1
number of ms main thread had to wait: 101
number of ms secondary thread had to wait: 101
PASS
Comment 4•5 years ago
|
||
Assignee | ||
Comment 5•5 years ago
|
||
(In reply to Nathan Froyd [:froydnj] from comment #4)
I'm guessing the intent of this test is to ensure that the function called
byPR_CallOnce
is only ever called once? And the underlying assumption
behind the test is that thePR_Sleep
call in the once-called function
would cause things to take 100ms+ on a single thread, and therefore that
only one thread should ever take 100ms to do its work? That's not a valid
assumption.
No, the intention isn't to test that the function is only called once.
The intention is to ensure, that the other threads have to WAIT until after the init has completed.
This code ensures that each thread that calls PR_CallOnce is delayed at least by the amount of time the init function sleeps.
Comment 6•5 years ago
|
||
(In reply to Kai Engert (:KaiE:) from comment #5)
(In reply to Nathan Froyd [:froydnj] from comment #4)
I'm guessing the intent of this test is to ensure that the function called
byPR_CallOnce
is only ever called once? And the underlying assumption
behind the test is that thePR_Sleep
call in the once-called function
would cause things to take 100ms+ on a single thread, and therefore that
only one thread should ever take 100ms to do its work? That's not a valid
assumption.No, the intention isn't to test that the function is only called once.
The intention is to ensure, that the other threads have to WAIT until after the init has completed.
Ah, I see. I saw all the code, but didn't fully process it.
Regardless, this intention is still backed by a false assumption: that all threads in the testcase have to wait in some way. The main thread can get through the PR_CallOnce
before the other thread even enters the necessary lock, and so the other thread will never have to wait.
Assignee | ||
Comment 7•5 years ago
|
||
Updated•2 years ago
|
Description
•