Changes between Version 37 and Version 38 of LightweightConcurrency


Ignore:
Timestamp:
May 18, 2012 4:48:04 PM (2 years ago)
Author:
kc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LightweightConcurrency

    v37 v38  
    8787                         Completed          -- SCont has run to completion 
    8888 
    89 setSContSwitchReason :: SContSwitchReason -> PTM () 
     89setSContSwitchReason :: SCont -> SContSwitchReason -> PTM () 
    9090getSContStatus       :: SCont -> PTM SContStatus 
    9191}}} 
    9292 
    93 Any attempt to switch to an SCont with status other than `SContSwitched Yielded` throws an exception. Primitive `setSContSwitchReason` updates the status of current SCont. This prevents the programmer from modifying the status of other SConts. Since setSContSwitchReason is a PTM action, the effect of updating the status takes place when the transaction commits and the control has switched to another SCont. This avoids any race conditions that might be involved in reading the status of an SCont before it has switched.  
     93Any attempt to switch to an SCont with status other than `SContSwitched Yielded` throws an exception. Primitive `setSContSwitchReason` updates the status of SCont. Since setSContSwitchReason is a PTM action, the effect of updating the status takes place when the transaction commits and the control has switched to another SCont. This avoids any race conditions that might be involved in reading the status of an SCont before it has switched.  
    9494 
    9595Before a switch operation, we expect the programmer to indicate the reason for switching through setScontSwitchReason. Exception is raised by the switch primitives if a switch reason has not been provided. When a switched SCont resumes execution, its status is automatically updated to `SContRunning`.  
     
    118118  sched :: PVar [SCont] <- -- get sched  
    119119  contents :: [SCont] <- readPVar sched  
     120  setSContSwitchReason sc Yielded -- sc is ready to be run 
    120121  writePVar $ contents ++ [sc] 
     122 
    121123 
    122124yieldControlAction :: PTM ()  
     
    132134}}} 
    133135 
    134  
     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. 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. 
    135137 
    136138== Capabilities and Tasks ==