Changes between Version 3 and Version 4 of Concurrency/DraftReportText


Ignore:
Timestamp:
Jan 16, 2007 1:10:01 PM (9 years ago)
Author:
simonmar@…
Comment:

mainly edits to bound threads

Legend:

Unmodified
Added
Removed
Modified
  • Concurrency/DraftReportText

    v3 v4  
    1818 * A thread that is not ''blocked'' will not be indefinitely delayed by the implementation.
    1919
    20 Where a thread is ''blocked'' if
     20where
    2121
    22  * the thread is waiting for an external resource that is currently not available (for example input
     22 * a thread is ''blocked'' if it is waiting for an external resource that is currently not available (for example input
    2323   from the console), or it is performing an operation that involves a shared resource and another thread
    24    currently has ownership of the resource (for example, output to a `Handle`).
     24   currently has ownership of the resource (for example, output to a shared `Handle`).
    2525
    2626This is called the ''fairness guarantee''.  An implementation technique that is often used to provide this fairness guarnatee is ''pre-emption'': running threads are periodically pre-empted in software in order to let other threads proceed.  There are other implementation techniques that also work; for example, hardware concurrency.  ('''ToDo''': move this text to a footnote or separate section?)
     
    6969== Bound threads (optional) ==
    7070
    71 '''ToDo'''.
    72 
    73 Bound threads allow a Haskell program more control over the mapping between Haskell threads and OS threads.  Such control is required for interacting with foreign code that makes use of thread-local state in the native OS threading model.  When foreign code uses OS thread-local state, the Haskell programmer needs to restrict calls to that foreign code to happen in a particular OS thread, which is what bound threads provide.
     71Bound threads allow a Haskell program more control over the mapping between Haskell threads and OS threads.  Such control is required for interacting with foreign code that makes use of thread-local state in the native OS threading model: when foreign code uses OS thread-local state, the Haskell programmer needs to restrict calls to that foreign code to happen in a particular OS thread.  Bound threads provide a lightweight way to allow the programmer enough control without imposing burdens on the implementation that would significantly reduce efficiency.
    7472
    7573Bound threads are an optional feature in Haskell'; the documentation for an implementation should state whether bound threads are supported or not.
     
    7775A Haskell thread can be either ''bound'' or ''unbound'', depending on how it was created:
    7876
     77 * `forkIO` creates ''unbound'' threads
     78
    7979 * Calls from foreign code to Haskell functions exposed by `foreign export` or `foreign import "wrapper"` create a
    8080   ''bound'' thread in which to run the computation.
    81 
    82  * `forkIO` creates ''unbound'' threads
    8381
    8482Whether a thread is bound or unbound affects how foreign calls are made:
     
    9088Note that a valid implementation of bound threads is one in which every Haskell thread is associated with a distinct OS thread, where in effect every thread is bound.  However, the `isCurrentThreadBound` operation (see below) should always return `False` for threads created by `forkIO`, regardless of the implementation, to aid portabilty.
    9189
    92 The following operations exported by `Control.Concurrent` are related to bound threads:
     90Also note that the above property of foreign calls made by a bound thread is the ''only'' requirement of the relationship between OS threads and Haskell threads.  It is completely unspecified which OS thread runs the Haskell code itself: the implementation is free to choose among a number of strategies here.
     91
     92The following operations exported by `Control.Concurrent` are related to bound threads ('''ToDo''' just link to the appropriate section of the library docs here?):
    9393
    9494{{{
     
    102102}}}
    103103
    104 This operation returns `False` if the current thread was created by `forkIO`, and `True` otherwise.
     104This operation returns `False` if the current thread was created by `forkIO`, and `True` otherwise.  If `supportsBoundThreads` is `False`, this function raises an exception ('''ToDo''' which one?).
    105105
    106106{{{
     
    108108}}}
    109109
    110 Like `forkIO`, `forkOS` creates a new Haskell thread to run the supplied `IO` action.  However, in the case of `forkOS`, the new Haskell thread is bound to a freshly created OS thread.  This is achieved by making a foreign call to create the new OS thread, and having the new OS thread invoke the `IO` action, thus creating a bound thread.
     110Like `forkIO`, `forkOS` creates a new Haskell thread to run the supplied `IO` action.  However, in the case of `forkOS`, the new Haskell thread is bound to a freshly created OS thread.  This is achieved by making a foreign call to create the new OS thread, and having the new OS thread invoke the `IO` action, thus creating a bound thread.  If `supportsBoundThreads` is `False`, this function raises an exception ('''ToDo''' which one?).