Rust concurrency question. I want to store a `read...
# development
h
Rust concurrency question. I want to store a
read_error_count: BTreeMap<String, usize>
field on
remote_cache::CommandRunner
. I think I want to wrap that in a
Mutex
? Iiuc, we only have one
CommandRunner
ever, but
run()
can be called by multiple different threads/tasks. I don't think I need an
Arc
because the type isn't being shared across different values?
e
The compiler will tell you right? That's the beauty here.
Try Rc, get a failure,because not Send or somesuch, go Arc.
h
Great point, thanks for the reminder. Turns out, we need
Mutex<>
to be able to mutate, and then
Arc<>
so that it's cloneable.
Arc<Mutex<BTreeMap<String, usize>>>
👍 1