@@ -118,15 +118,11 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
118
118
///
119
119
/// const N: usize = 3;
120
120
///
121
- /// // Some data to work with in multiple threads.
122
121
/// let data_mutex = Arc::new(Mutex::new(vec![1, 2, 3, 4]));
123
- /// // The result of all the work across all threads.
124
122
/// let res_mutex = Arc::new(Mutex::new(0));
125
123
///
126
- /// // Threads other than the main thread.
127
124
/// let mut threads = Vec::with_capacity(N);
128
125
/// (0..N).for_each(|_| {
129
- /// // Getting clones for the mutexes.
130
126
/// let data_mutex_clone = Arc::clone(&data_mutex);
131
127
/// let res_mutex_clone = Arc::clone(&res_mutex);
132
128
///
@@ -135,10 +131,6 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
135
131
/// // This is the result of some important and long-ish work.
136
132
/// let result = data.iter().fold(0, |acc, x| acc + x * 2);
137
133
/// data.push(result);
138
- /// // We drop the `data` explicitely because it's not necessary anymore
139
- /// // and the thread still has work to do. This allow other threads to
140
- /// // start working on the data immediately, without waiting
141
- /// // for the rest of the unrelated work to be done here.
142
134
/// drop(data);
143
135
/// *res_mutex_clone.lock().unwrap() += result;
144
136
/// }));
@@ -153,9 +145,9 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
153
145
/// // start working on the data immediately, without waiting
154
146
/// // for the rest of the unrelated work to be done here.
155
147
/// //
156
- /// // It's even more important here because we `.join` the threads after that.
157
- /// // If we had not dropped the lock, a thread could be waiting forever for
158
- /// // it, causing a deadlock.
148
+ /// // It's even more important here than in the threads because we `.join` the
149
+ /// // threads after that. If we had not dropped the lock, a thread could be
150
+ /// // waiting forever for it, causing a deadlock.
159
151
/// drop(data);
160
152
/// // Here the lock is not assigned to a variable and so, even if the scope
161
153
/// // does not end after this line, the mutex is still released:
0 commit comments