about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-29 21:23:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-29 21:23:56 -0700
commit8bafc90dfda6cd170343ad1d7351d418f38189ae (patch)
tree97c8fe5b5ebe9b7b40ca063dba4e3c9d6231e924
parentef69c56c82e85e83014605f501110697d81bcdc1 (diff)
downloadmu-8bafc90dfda6cd170343ad1d7351d418f38189ae.tar.gz
3609
-rw-r--r--html/075channel.mu.html4
-rw-r--r--html/088file.mu.html6
-rw-r--r--html/089scenario_filesystem.cc.html2
3 files changed, 10 insertions, 2 deletions
diff --git a/html/075channel.mu.html b/html/075channel.mu.html
index 42e8fda8..7b9ade33 100644
--- a/html/075channel.mu.html
+++ b/html/075channel.mu.html
@@ -45,6 +45,10 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 <span class="Comment">#   b) Writing to a channel implicitly performs a deep copy. This prevents</span>
 <span class="Comment">#   addresses from being shared between routines, and therefore eliminates all</span>
 <span class="Comment">#   possibility of race conditions.</span>
+<span class="Comment">#</span>
+<span class="Comment"># There's still a narrow window for race conditions: the ingredients passed in</span>
+<span class="Comment"># to 'start-running'. Pass only channels into routines and you should be fine.</span>
+<span class="Comment"># Any other mutable ingredients will require locks.</span>
 
 <span class="muScenario">scenario</span> channel [
   run [
diff --git a/html/088file.mu.html b/html/088file.mu.html
index 26fa0c7c..46d9363a 100644
--- a/html/088file.mu.html
+++ b/html/088file.mu.html
@@ -35,6 +35,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 <span class="Comment"># are thus easier to test.</span>
 
 <span class="muData">container</span> resources [
+  lock:bool
   data:&amp;:@:resource
 ]
 
@@ -117,7 +118,6 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   <span class="Delimiter">{</span>
     <span class="muControl">break-unless</span> resources
     <span class="Comment"># fake file system</span>
-    <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span>
     routine-id <span class="Special">&lt;-</span> start-running transmit-to-fake-file resources, filename, source
     <span class="muControl">reply</span>
   <span class="Delimiter">}</span>
@@ -142,6 +142,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 <span class="muRecipe">def</span> transmit-to-fake-file resources:&amp;:resources, filename:text, source:&amp;:source:char<span class="muRecipe"> -&gt; </span>resources:&amp;:resources, source:&amp;:source:char [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
+  lock:location <span class="Special">&lt;-</span> get-location *resources, <span class="Constant">lock:offset</span>
+  wait-for-reset-then-set lock
   <span class="Comment"># compute new file contents</span>
   buf:&amp;:buffer <span class="Special">&lt;-</span> new-buffer<span class="Constant"> 30</span>
   <span class="Delimiter">{</span>
@@ -166,6 +168,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     found?:bool <span class="Special">&lt;-</span> equal filename, curr-filename
     <span class="muControl">loop-unless</span> found?
     put-index *data, i, new-resource
+    reset lock
     <span class="muControl">reply</span>
   <span class="Delimiter">}</span>
   <span class="Comment"># if file didn't already exist, make room for it</span>
@@ -182,6 +185,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   <span class="Delimiter">}</span>
   <span class="Comment"># write new file</span>
   put-index *new-data, len, new-resource
+  reset lock
 ]
 </pre>
 </body>
diff --git a/html/089scenario_filesystem.cc.html b/html/089scenario_filesystem.cc.html
index d1fb007d..608f9c25 100644
--- a/html/089scenario_filesystem.cc.html
+++ b/html/089scenario_filesystem.cc.html
@@ -258,7 +258,7 @@ string munge_resources_contents<span class="Delimiter">(</span><span class="Norm
   trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;storing refcount 1 in location &quot;</span> &lt;&lt; resources_data_address &lt;&lt; end<span class="Delimiter">();</span>
   <span class="Comment">// wrap the resources data in a 'resources' object</span>
   <span class="Normal">int</span> resources_address = allocate<span class="Delimiter">(</span>size_of_resources<span class="Delimiter">());</span>
-  curr = resources_address+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>
+  curr = resources_address+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'data' element</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span>
   put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> resources_data_address<span class="Delimiter">);</span>
   trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;storing resources data address &quot;</span> &lt;&lt; resources_data_address &lt;&lt; <span class="Constant">&quot; in location &quot;</span> &lt;&lt; curr &lt;&lt; end<span class="Delimiter">();</span>
   put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> resources_address<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span>  <span class="Comment">// initialize refcount</span>