]> git.lizzy.rs Git - rust.git/commitdiff
Catch thread in example
authorStefan Schindler <dns2utf8@estada.ch>
Mon, 16 May 2016 16:54:12 +0000 (18:54 +0200)
committerStefan Schindler <dns2utf8@estada.ch>
Thu, 19 May 2016 21:05:08 +0000 (23:05 +0200)
 - Consume result of thread join()
 - Add link to threading model

src/libcore/sync/atomic.rs

index 52ba8d9a631d89459534b8b093fadae84cfaa96f..1bdab88d71da08226d7238b0c2a1c32106ad7e4a 100644 (file)
@@ -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
 //!     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);
+//!     }
 //! }
 //! ```
 //!