summary refs log tree commit diff stats
path: root/doc/spawn.txt
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-10-02 02:33:59 +0200
committerAraq <rumpf_a@web.de>2014-10-02 02:33:59 +0200
commit2c1f3f75f5d37db810113cf37e1b38c3b7b09ee7 (patch)
tree70b805d8f0e4d62c2e84384d605c084661dd5334 /doc/spawn.txt
parente9dec2feedc25afd8af8fc3db3131ffbb4b284a7 (diff)
downloadNim-2c1f3f75f5d37db810113cf37e1b38c3b7b09ee7.tar.gz
manual split up into multiple files; documented the new concurrency system
Diffstat (limited to 'doc/spawn.txt')
-rw-r--r--doc/spawn.txt62
1 files changed, 30 insertions, 32 deletions
diff --git a/doc/spawn.txt b/doc/spawn.txt
index b2496285f..fb2f851c7 100644
--- a/doc/spawn.txt
+++ b/doc/spawn.txt
@@ -19,6 +19,36 @@ read prematurely within a ``parallel`` section and so there is no need for
 the overhead of an indirection via ``FlowVar[T]`` to ensure correctness.
 
 
+Spawn statement
+===============
+
+A standalone ``spawn`` statement is a simple construct. It executes
+the passed expression on the thread pool and returns a `data flow variable`:idx:
+``FlowVar[T]`` that can be read from. The reading with the ``^`` operator is
+**blocking**. However, one can use ``awaitAny`` to wait on multiple flow
+variables at the same time:
+
+.. code-block:: nim
+  import threadpool, ...
+  
+  # wait until 2 out of 3 servers received the update:
+  proc main =
+    var responses = newSeq[RawFlowVar](3)
+    for i in 0..2:
+      responses[i] = spawn tellServer(Update, "key", "value")
+    var index = awaitAny(responses)
+    assert index >= 0
+    responses.del(index)
+    discard awaitAny(responses)
+
+Data flow variables ensure that no data races
+are possible. Due to technical limitations not every type ``T`` is possible in
+a data flow variable: ``T`` has to be of the type ``ref``, ``string``, ``seq``
+or of a type that doesn't contain a type that is garbage collected. This
+restriction will be removed in the future.
+
+
+
 Parallel statement
 ==================
 
@@ -64,35 +94,3 @@ restrictions / changes:
 * Slices are optimized so that no copy is performed. This optimization is not
   yet performed for ordinary slices outside of a ``parallel`` section. Slices
   are also special in that they currently do not support negative indexes!
-
-
-
-
-Spawn statement
-===============
-
-A standalone ``spawn`` statement is a simple construct. It executes
-the passed expression on the thread pool and returns a `data flow variable`:idx:
-``FlowVar[T]`` that can be read from. The reading with the ``^`` operator is
-**blocking**. However, one can use ``awaitAny`` to wait on multiple flow
-variables at the same time:
-
-.. code-block:: nim
-  import threadpool, ...
-  
-  # wait until 2 out of 3 servers received the update:
-  proc main =
-    var responses = newSeq[RawFlowVar](3)
-    for i in 0..2:
-      responses[i] = spawn tellServer(Update, "key", "value")
-    var index = awaitAny(responses)
-    assert index >= 0
-    responses.del(index)
-    discard awaitAny(responses)
-
-Like the ``parallel`` statement data flow variables ensure that no data races
-are possible. Due to technical limitations not every type ``T`` is possible in
-a data flow variable: ``T`` has to be of the type ``ref``, ``string``, ``seq``
-or of a type that doesn't contain a type that is garbage collected. This
-restriction will be removed in the future.
-