Changes between Version 26 and Version 27 of LightweightConcurrency


Ignore:
Timestamp:
May 17, 2012 11:11:39 PM (3 years ago)
Author:
kc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LightweightConcurrency

    v26 v27  
    7676The type of the transaction that contains switchTo is PTM string, and atomically performing the transaction is expected to return a String value. But the value returned when the current SCont resumes execution (after switchTo) is a (). Our solution is to make switchTo return a `error "Attempting to use return value of a switched transaction"`, and any attempt to use the return value throws a runtime error. 
    7777 
    78 Of course, care must be taken to ensure that the control does not switch to an SCont that is either running or completed. 
     78==== SCont Status ==== 
     79 
     80Of course, care must be taken to ensure that the control does not switch to an SCont that is either running, blocked on an MVar, or completed. But how do we know whether the given SCont is ready to run? We expect the scheduler writer or library implementer to indicate the status of SCont before switching. SCont status API is show below. 
     81 
     82{{{ 
     83data SContStatus = SContRunning |           -- SCont is currently running 
     84                   SContKilled  |           -- SCont was killed by an (asynchronous) exception 
     85                   SContSwitched SContSwitchReason 
     86data SContSwitchReason = Yielded |          -- SCont has yielded, but runnable 
     87                         BlockedInHaskell | -- SCont is blocked on a user-level concurrent data structure  
     88                         BlockedInRTS |     -- SCont is blocked on a foreign call, blackhole, etc,. 
     89                         Completed          -- SCont has run to completion 
     90 
     91setSContSwitchReason :: SContSwitchReason -> PTM () 
     92getSContStatus       :: SCont -> PTM SContStatus 
     93}}} 
     94 
     95Primitive `setSContSwitchReason` updates the status of current SCont. Notice that this prevents the programmer from modifying the status of other SConts and is a PTM action. Thus, the effect of updating the status takes place when the transaction commits and the control has switches to another SCont. This avoids any race conditions that might be involved in reading the status of an SCont before it has completed switch operation.  
    7996 
    8097=== Capabilities and Tasks ===