4 ms·
> You can see how this makes it impossible to mutate the state without remembering to aquire the lock. Not quite true. Looking at the type signature of e.g. RW
by 45g 13y ago
> You can see how this makes it impossible to mutate the state without remembering to aquire the lock.
Not quite true. Looking at the type signature of e.g. RWArc::write I see this:
fn write<U>(&self, blk: |x: &mut T| -> U) -> U
which means I could probably do:
let mut n = local_arc.write(|nums| {
nums[num] += 1;
return ~(*nums);
});
n[2] = 42;
- deleted 13y ago[deleted]
- eridius 13y agoYou're not letting anything escape. You're copying `nums` and then mutating your copy. And this only works because `nums` can be implicitly copied like this. If you changed it from `[int, ..3]` to `~[int]` you'd get a compiler error (as `~[T]` cannot be implicitly copied).