Changes between Version 11 and Version 12 of Commentary/Rts/Scheduler


Ignore:
Timestamp:
Oct 17, 2006 2:08:14 PM (8 years ago)
Author:
simonmar
Comment:

add stuff about sparks

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/Scheduler

    v11 v12  
    209209}}} 
    210210 
     211== Sparks and the par operator == 
     212 
     213Source files: [[GhcFile(rts/Sparks.c)]], [[GhcFile(rts/Sparks.h)]]. 
     214 
     215The [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Parallel.html#v%3Apar par] operator is used for annotating computations that could be evaluated in parallel.  See also [http://www.haskell.org/ghc/docs/latest/html/users_guide/lang-parallel.html Parallel Haskell] in the GHC User's Guide. 
     216 
     217Par itself is implemented in terms of the `par#` primop, which the code generator compiles into a call to `newSpark` in [[GhcFile(rts/Sparks.c)]]. 
     218 
     219Par doesn't actually create a new thread immediately; instead it places a pointer to its first argument in the ''spark pool''.  The spark pool is a circular buffer, when it is full we have the choice of either overwriting the oldest entry or dropping the new entry - currently we drop the new entry (see code for `newSpark`).  Each capability has its own spark pool, so this operation can be performed without taking a lock. 
     220 
     221So how does the spark turn into a thread?  When the scheduler spots that the current capability has no runnable threads, it checks the spark pool, and if there is a valid spark (a spark that points to a THUNK), then the spark is turned into a real thread and placed on the run queue: see `createSparkThread` in [[GhcFile(rts/Sparks.c)]].  Also, the scheduler attempts to share its available sparks with any other idle capabilities: see `schedulePushWork` in [[GhcFile(rts/Scheduler.c)]]. 
     222 
    211223== Affinity and migration == 
    212224