Skip to content

Commit 22615ad

Browse files
committed
Catch thread in example
- Consume result of thread join() - Add link to threading model
1 parent 764ef92 commit 22615ad

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libcore/sync/atomic.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
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
@@ -48,12 +49,16 @@
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
//!

0 commit comments

Comments
 (0)