Closed Bug 609837 Opened 14 years ago Closed 13 years ago

VMPI threading extensions require a yield-like function

Categories

(Tamarin Graveyard :: Virtual Machine, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: siwilkin, Unassigned)

References

Details

Attachments

(1 file, 4 obsolete files)

A non-priority-inverting yield will be very useful for building well-behaved busy-waiting.
Blocks: 575544
Blocks: 562687
Attached patch Initial Patch (obsolete) — Splinter Review
Attached patch Latest patch (obsolete) — Splinter Review
Attachment #489741 - Attachment is obsolete: true
Attachment #494807 - Flags: review?(kpalacz)
Attachment #494807 - Flags: feedback?(stan)
Attachment #494807 - Flags: review?(kpalacz) → review+
Attachment #494807 - Flags: superreview?(edwsmith)
Comment on attachment 494807 [details] [diff] [review]
Latest patch

Looking at this as a newcomer, I read the docs on VMPI_yeild(), and wonder what eactly it's good for, given the contract on different platforms is so loose.  

* are there cases where it MUST be used? what are they?
* what is guaranteed to happen, even if implementations vary so much?
Attachment #494807 - Flags: superreview?(edwsmith) → superreview+
(In reply to comment #3)
> Comment on attachment 494807 [details] [diff] [review]
> Latest patch
> 
> Looking at this as a newcomer, I read the docs on VMPI_yeild(), and wonder what
> eactly it's good for, given the contract on different platforms is so loose.  
> 
> * are there cases where it MUST be used? what are they?
> * what is guaranteed to happen, even if implementations vary so much?

A yield is useful within busy-waiting loops.
However, there is no requirement that it *must* be used, except on platforms without a pre-emptive thread scheduler. I understand that all of our platforms do have a pre-emptive scheduler, so its application will only be an optimization.

I'd really like the yield function's contract to be:
Hints to the scheduler that the running thread is waiting on some condition to be updated by another thread, and importantly, that the condition is already fulfilled or will be very soon (i.e. within a scheduling quantum). Hence the running thread should temporarily get out of the way (yield) for the other thread to run. This should not penalize the regular scheduling of either thread, and particularly we want the yielding thread to start running again as soon as possible as it can now make forward progress.

On Windows the SwitchToThread function is close enough to the above idea. All the other platforms aren't particularly clear about when the yielding thread will start running again (getting put to the back of runnable queue is typical).

In most cases you should be using regular wait/notify to synchronize threads in this way. But in some parts of the synchronization implementation itself you cannot, i.e. spin-lock implementation, safepoint wait etc. So the yield is better than nothing.
Attached patch Latest. More docs. (obsolete) — Splinter Review
Added some more docs that summarizes my reply to Ed above.
Attachment #494807 - Attachment is obsolete: true
Attachment #494807 - Flags: feedback?(stan)
Fixes the WinCE build where SwitchToThread() is not available (Sleep(1) is used instead).

Fixes the Solaris build so that the rt library is linked (required for the sched_yield() function)
Attachment #497757 - Attachment is obsolete: true
Attachment #499307 - Attachment is obsolete: true
Comment on attachment 499317 [details] [diff] [review]
Latest. Rebased to TR-5705


Requested another SR as I've had to link a new library (rt) in the Solaris build.
Attachment #499317 - Flags: superreview?(edwsmith)
Comment on attachment 499317 [details] [diff] [review]
Latest. Rebased to TR-5705

Is there anything directly testable here, or is usage from upper layers good enough?
Attachment #499317 - Flags: superreview?(edwsmith) → superreview+
(In reply to comment #9)
> Is there anything directly testable here, or is usage from upper layers good
> enough?

The safepoint selftests directly call VMPI_threadYield(), this should be good enough.
changeset: 5843:891ad70c3012
user:      kpalacz@adobe.com
summary:   Bug 609837 - VMPI threading extensions require a yield-like function (a=swilkin,r+kpalacz,sr+edwsmith)

http://hg.mozilla.org/tamarin-redux/rev/891ad70c3012
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: