@@ -119,7 +119,7 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
119
119
/// const N: usize = 3;
120
120
///
121
121
/// // Some data to work with in multiple threads.
122
- /// let data_mutex = Arc::new(Mutex::new([1, 2, 3, 4]));
122
+ /// let data_mutex = Arc::new(Mutex::new(vec! [1, 2, 3, 4]));
123
123
/// // The result of all the work across all threads.
124
124
/// let res_mutex = Arc::new(Mutex::new(0));
125
125
///
@@ -131,9 +131,10 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
131
131
/// let res_mutex_clone = Arc::clone(&res_mutex);
132
132
///
133
133
/// threads.push(thread::spawn(move || {
134
- /// let data = * data_mutex_clone.lock().unwrap();
134
+ /// let mut data = data_mutex_clone.lock().unwrap();
135
135
/// // This is the result of some important and long-ish work.
136
136
/// let result = data.iter().fold(0, |acc, x| acc + x * 2);
137
+ /// data.push(result);
137
138
/// // We drop the `data` explicitely because it's not necessary anymore
138
139
/// // and the thread still has work to do. This allow other threads to
139
140
/// // start working on the data immediately, without waiting
@@ -143,9 +144,10 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
143
144
/// }));
144
145
/// });
145
146
///
146
- /// let data = * data_mutex.lock().unwrap();
147
+ /// let mut data = data_mutex.lock().unwrap();
147
148
/// // This is the result of some important and long-ish work.
148
149
/// let result = data.iter().fold(0, |acc, x| acc + x * 2);
150
+ /// data.push(result);
149
151
/// // We drop the `data` explicitely because it's not necessary anymore
150
152
/// // and the thread still has work to do. This allow other threads to
151
153
/// // start working on the data immediately, without waiting
@@ -166,7 +168,7 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
166
168
/// .expect("The thread creating or execution failed !")
167
169
/// });
168
170
///
169
- /// assert_eq!(*res_mutex.lock().unwrap(), 80 );
171
+ /// assert_eq!(*res_mutex.lock().unwrap(), 800 );
170
172
/// ```
171
173
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
172
174
#[ cfg_attr( not( test) , rustc_diagnostic_item = "mutex_type" ) ]
0 commit comments