diff options
| author | Stefan Schindler <dns2utf8@estada.ch> | 2016-05-16 18:54:12 +0200 |
|---|---|---|
| committer | Stefan Schindler <dns2utf8@estada.ch> | 2016-05-19 23:05:08 +0200 |
| commit | 22615adf02578d7b88a36e98275d4e63da4d5ec6 (patch) | |
| tree | ff62bfbb84fe1b50dd1050fc3d60a55be71ef023 /src/libcore/sync | |
| parent | 764ef92ae7a26cbb9c2121de3812a0a17739f65f (diff) | |
| download | rust-22615adf02578d7b88a36e98275d4e63da4d5ec6.tar.gz rust-22615adf02578d7b88a36e98275d4e63da4d5ec6.zip | |
Catch thread in example
- Consume result of thread join() - Add link to threading model
Diffstat (limited to 'src/libcore/sync')
| -rw-r--r-- | src/libcore/sync/atomic.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 52ba8d9a631..1bdab88d71d 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -26,8 +26,9 @@ //! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations //! //! Atomic variables are safe to share between threads (they implement `Sync`) -//! but they do not themselves provide the mechanism for sharing. The most -//! common way to share an atomic variable is to put it into an `Arc` (an +//! but they do not themselves provide the mechanism for sharing and follow the +//! [threading model](../../../std/thread/index.html#the-threading-model) of rust. +//! The most common way to share an atomic variable is to put it into an `Arc` (an //! atomically-reference-counted shared pointer). //! //! Most atomic types may be stored in static variables, initialized using @@ -48,12 +49,16 @@ //! let spinlock = Arc::new(AtomicUsize::new(1)); //! //! let spinlock_clone = spinlock.clone(); -//! thread::spawn(move|| { +//! let thread = thread::spawn(move|| { //! spinlock_clone.store(0, Ordering::SeqCst); //! }); //! //! // Wait for the other thread to release the lock //! while spinlock.load(Ordering::SeqCst) != 0 {} +//! +//! if let Err(panic) = thread.join() { +//! println!("Thread had an error: {:?}", panic); +//! } //! } //! ``` //! |
