Reputation: 3410
Do locks exist in Rust? The manual briefly mentions it but I can't find any implementation in the standard library. If they exist, how do we use one?
Upvotes: 1
Views: 994
Reputation: 102066
There are mutexes (and condition variables, etc.) in extra::sync
, although one should use the higher-level wrappers for shared memory that Eric Holk mentions in extra::arc
if shared memory is all you need.
Upvotes: 2
Reputation: 1386
Locks in Rust are mostly used to implement low level things in the runtime. As @chris-morgan said, you generally don't need locks. Normally the right way to synchronize between tasks is by passing messages.
If message passing doesn't meet your needs, ARCs might work: http://static.rust-lang.org/doc/master/extra/arc/index.html
Upvotes: 3