From 8bafc90dfda6cd170343ad1d7351d418f38189ae Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 29 Oct 2016 21:23:56 -0700 Subject: 3609 --- html/075channel.mu.html | 4 ++++ html/088file.mu.html | 6 +++++- html/089scenario_filesystem.cc.html | 2 +- 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 # b) Writing to a channel implicitly performs a deep copy. This prevents # addresses from being shared between routines, and therefore eliminates all # possibility of race conditions. +# +# There's still a narrow window for race conditions: the ingredients passed in +# to 'start-running'. Pass only channels into routines and you should be fine. +# Any other mutable ingredients will require locks. scenario 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 # are thus easier to test. container resources [ + lock:bool data:&:@:resource ] @@ -117,7 +118,6 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color { break-unless resources # fake file system - # beware: doesn't support multiple concurrent writes yet routine-id <- start-running transmit-to-fake-file resources, filename, source reply } @@ -142,6 +142,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color def transmit-to-fake-file resources:&:resources, filename:text, source:&:source:char -> resources:&:resources, source:&:source:char [ local-scope load-ingredients + lock:location <- get-location *resources, lock:offset + wait-for-reset-then-set lock # compute new file contents buf:&:buffer <- new-buffer 30 { @@ -166,6 +168,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color found?:bool <- equal filename, curr-filename loop-unless found? put-index *data, i, new-resource + reset lock reply } # if file didn't already exist, make room for it @@ -182,6 +185,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color } # write new file put-index *new-data, len, new-resource + reset lock ] 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((9999, "mem") << "storing refcount 1 in location " << resources_data_address << end(); // wrap the resources data in a 'resources' object int resources_address = allocate(size_of_resources()); - curr = resources_address+/*skip refcount*/1; + curr = resources_address+/*skip refcount*/1+/*offset of 'data' element*/1; put(Memory, curr, resources_data_address); trace(9999, "mem") << "storing resources data address " << resources_data_address << " in location " << curr << end(); put(Memory, resources_address, 1); // initialize refcount -- cgit 1.4.1-2-gfad0