5 ms·
The simplest (and often best) option is to use the Arc<Mutex<MyStruct>> pattern. The Arc is an async reference counter that allows multiple ownership. And the
by brink 6y ago
The simplest (and often best) option is to use the Arc<Mutex<MyStruct>> pattern.
The Arc is an async reference counter that allows multiple ownership. And the nested Mutex enforces only one mutable borrow at a time.
- efficax 6y agoI think you mean that Arc is an atomic reference counter (it uses atomic cpu instructions to prevent race conditions when incrementing and decrementing the ref count)
- brink 6y agoAh yes, sorry. I remember it in my head with "async", but you're right. :)
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]