From cdf2822743b3beeb37ebc3deea8e08b6130698c5 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 12 May 2018 10:22:26 -0700 Subject: 4242 - get rid of refcounts entirely We're going to lean back into the experiment of commit 4179 back in Jan. If we delete memory it's up to us to ensure no pointers into it survive. Since deep-copy depends on our refcounting infrastructure, it's gone as well. So we're going to have to start watching out for pointers shared over channels. --- 075channel.mu | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to '075channel.mu') diff --git a/075channel.mu b/075channel.mu index 1f8248ef..422b2ab8 100644 --- a/075channel.mu +++ b/075channel.mu @@ -1,18 +1,11 @@ # Mu synchronizes between routines using channels rather than locks, like # Erlang and Go. # -# Key properties of channels: +# The key property of channels: Writing to a full channel or reading from an +# empty one will put the current routine in 'waiting' state until the +# operation can be completed. # -# a) Writing to a full channel or reading from an empty one will put the -# current routine in 'waiting' state until the operation can be completed. -# -# 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 inputs passed in -# to 'start-running'. Pass only channels into routines and you should be fine. -# Any other mutable inputs will require locks. +# Beware of addresses passed into channels. They can cause race conditions. scenario channel [ run [ @@ -92,8 +85,7 @@ def write out:&:sink:_elem, val:_elem -> out:&:sink:_elem [ # store a deep copy of val circular-buffer:&:@:_elem <- get *chan, data:offset free:num <- get *chan, first-free:offset - val-copy:_elem <- deep-copy val # on this instruction rests all Mu's concurrency-safety - *circular-buffer <- put-index *circular-buffer, free, val-copy + *circular-buffer <- put-index *circular-buffer, free, val # mark its slot as filled free <- add free, 1 { -- cgit 1.4.1-2-gfad0