File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 2626//! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations
2727//!
2828//! Atomic variables are safe to share between threads (they implement `Sync`)
29- //! but they do not themselves provide the mechanism for sharing. The most
30- //! common way to share an atomic variable is to put it into an `Arc` (an
29+ //! but they do not themselves provide the mechanism for sharing and follow the
30+ //! [threading model](../../../std/thread/index.html#the-threading-model) of rust.
31+ //! The most common way to share an atomic variable is to put it into an `Arc` (an
3132//! atomically-reference-counted shared pointer).
3233//!
3334//! Most atomic types may be stored in static variables, initialized using
4849//! let spinlock = Arc::new(AtomicUsize::new(1));
4950//!
5051//! let spinlock_clone = spinlock.clone();
51- //! thread::spawn(move|| {
52+ //! let thread = thread::spawn(move|| {
5253//! spinlock_clone.store(0, Ordering::SeqCst);
5354//! });
5455//!
5556//! // Wait for the other thread to release the lock
5657//! while spinlock.load(Ordering::SeqCst) != 0 {}
58+ //!
59+ //! if let Err(panic) = thread.join() {
60+ //! println!("Thread had an error: {:?}", panic);
61+ //! }
5762//! }
5863//! ```
5964//!
You can’t perform that action at this time.
0 commit comments