Changes between Version 42 and Version 43 of LightweightConcurrency


Ignore:
Timestamp:
May 18, 2012 8:44:44 PM (2 years ago)
Author:
kc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LightweightConcurrency

    v42 v43  
    134134}}} 
    135135 
    136 The implementation is pretty straight-forward; scheduleSContAction appends the given scont to the back of the list, and yieldControlAction picks an SCont from the front of the list and switches to it. Notice that scheduleSContAction returns while yieldControlAction does not. We expect every user-level thread (SCont) to be associated with a scheduler. Typically, when a new SCont is created, it is immediately associated with a scheduler. 
     136The implementation is pretty straight-forward; scheduleSContAction appends the given scont to the back of the list, and yieldControlAction picks an SCont from the front of the list and switches to it. Having the scheduler actions as PTM actions ensures that the operations on the scheduler are always properly synchronized. Notice that scheduleSContAction returns while yieldControlAction does not. We expect every user-level thread (SCont) to be associated with a scheduler. Typically, when a new SCont is created, it is immediately associated with a scheduler. 
    137137 
    138138== User-level concurrency == 
     
    150150setYCA = setYieldControlAction 
    151151}}} 
     152 
     153Primitive `yield` appends the current SCont to the scheduler, picks the next SCont from the scheduler and switches to it. We utilize the scheduler actions to achieve this. The implementation of yield is shown below. It is important to notice that yield does not assume anything about the implementation of the scheduler except for the scheduler actions. Hence, there is no need to re-implement yield primitive for every scheduler, thus minimizing the overhead of implementing new schedulers. 
    152154 
    153155{{{ 
     
    163165  switchToNext 
    164166}}} 
     167 
     168Primitive `forkIO` also follows the strategy of utilizing scheduler actions. The implementation of forkIO is shown below.  
    165169 
    166170{{{ 
     
    189193}}} 
    190194 
    191 Notice that the type signatures are similar to their counterparts in Control.Concurrent. 
     195Here, the thread that invokes forkIO initializes the new SCont with its own scheduler actions, and appends it to the scheduler. After the newly created SCont finishes execution, the control must switch to another thread in the scheduler. This is captured by the `epilogue`. 
    192196 
    193197=== MVars ===