https://pantsbuild.org/ logo
#development
Title
# development
h

hundreds-father-404

03/19/2021, 12:47 AM
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

enough-analyst-54434

03/19/2021, 12:53 AM
The compiler will tell you right? That's the beauty here.
Try Rc, get a failure,because not Send or somesuch, go Arc.
h

hundreds-father-404

03/19/2021, 1:07 AM
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