Changes between Version 3 and Version 4 of Concurrency/DraftReportText
- Timestamp:
- 01/16/07 05:10:01 (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Concurrency/DraftReportText
v3 v4 18 18 * A thread that is not ''blocked'' will not be indefinitely delayed by the implementation. 19 19 20 Where a thread is ''blocked'' if 20 where 21 21 22 * the threadis waiting for an external resource that is currently not available (for example input22 * a thread is ''blocked'' if it is waiting for an external resource that is currently not available (for example input 23 23 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`). 25 25 26 26 This 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?) … … 69 69 == Bound threads (optional) == 70 70 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. 71 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. Bound threads provide a lightweight way to allow the programmer enough control without imposing burdens on the implementation that would significantly reduce efficiency. 74 72 75 73 Bound threads are an optional feature in Haskell'; the documentation for an implementation should state whether bound threads are supported or not. … … 77 75 A Haskell thread can be either ''bound'' or ''unbound'', depending on how it was created: 78 76 77 * `forkIO` creates ''unbound'' threads 78 79 79 * Calls from foreign code to Haskell functions exposed by `foreign export` or `foreign import "wrapper"` create a 80 80 ''bound'' thread in which to run the computation. 81 82 * `forkIO` creates ''unbound'' threads83 81 84 82 Whether a thread is bound or unbound affects how foreign calls are made: … … 90 88 Note 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. 91 89 92 The following operations exported by `Control.Concurrent` are related to bound threads: 90 Also 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 92 The following operations exported by `Control.Concurrent` are related to bound threads ('''ToDo''' just link to the appropriate section of the library docs here?): 93 93 94 94 {{{ … … 102 102 }}} 103 103 104 This operation returns `False` if the current thread was created by `forkIO`, and `True` otherwise. 104 This 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?). 105 105 106 106 {{{ … … 108 108 }}} 109 109 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. 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. If `supportsBoundThreads` is `False`, this function raises an exception ('''ToDo''' which one?).
