Arc - Synchronization #3020
Locked
tomasrodathg
started this conversation in
Ideas
Replies: 1 comment
-
Where is mojo stdlib.sync.Mutex? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
/memory/arc.mojo
Is this comment still applicable? I'm not sure I fully understand it. An Arc offers no exclusivity on read-write access, it rather just helps with a thread-safe tracking of the lifetime of a pointer. Giving mutable access to an Arc would just open up room for race conditions.
I'd potentially argue that this should follow a similar structure to Rust's std whereby the module is moved to a "synchronization" (sync, thread...) module rather than memory and an Arc should always be immutable and provide with immutable references to inner values. Any mutability should be done via a thread-safe container around the inner-element and that requires the implementation of rw-locked structures, mutex...
I'm also not entirely sure how Mojo handles thread aborts and panics as that's something to consider in a synchronization primitive. Does a panic on a thread lead to the del meta method being called? If not you may end up in scenarios where an Arc will never go back to a count of 0 which will inevitably cause memory leaks
'memory' is likely the module for non-thread safe structures, maybe it's the place for a non-atomic reference counted container (akin to RC) and containers for non-thread safe inner-mutability like an unsafe ref cell.
Beta Was this translation helpful? Give feedback.
All reactions