Results for “Threads & shared ownership”
Small, practical examples. Search by task or narrow things down below.
Initialize shared data once
Initialize shared data once in a complete Rust program using the standard library.
Rust✓ Tested
Protect shared mutable state with a mutex
Protect shared mutable state with a mutex in a complete Rust program using the standard library.
Rust✓ Tested
Borrow local data in a scoped thread
Borrow local data in a scoped thread in a complete Rust program using the standard library.
Rust✓ Tested
Join a worker thread and read its result
Join a worker thread and read its result in a complete Rust program using the standard library.
Rust✓ Tested
Move owned data into a worker
Move owned data into a worker in a complete Rust program using the standard library.
Rust✓ Tested
Read a channel until all senders close
Read a channel until all senders close in a complete Rust program using the standard library.
Rust✓ Tested
Send a value through a channel
Send a value through a channel in a complete Rust program using the standard library.
Rust✓ Tested
Share immutable data with Arc
Share immutable data with Arc in a complete Rust program using the standard library.
Rust✓ Tested
Update an atomic counter
Update an atomic counter in a complete Rust program using the standard library.
Rust✓ Tested
Observe shared ownership without extending its lifetime
C++: A weak_ptr can be locked while an owner exists and becomes expired after the last owner is released.
C++✓ Tested
Share ownership with a counted smart pointer
C++: Copies of shared_ptr keep the owned value alive until the last owner is released.
C++✓ Tested
Increment a shared counter safely
C++: Atomic increments prevent lost updates when two threads change the same counter.
C++✓ Tested