We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec003fd commit c9b9c17Copy full SHA for c9b9c17
src/tools/miri/tests/pass/concurrency/scope.rs
@@ -0,0 +1,24 @@
1
+use std::thread;
2
+
3
+fn main() {
4
+ let mut a = vec![1, 2, 3];
5
+ let mut x = 0;
6
7
+ thread::scope(|s| {
8
+ s.spawn(|| {
9
+ // We can borrow `a` here.
10
+ let _s = format!("hello from the first scoped thread: {a:?}");
11
+ });
12
13
+ let _s = format!("hello from the second scoped thread");
14
+ // We can even mutably borrow `x` here,
15
+ // because no other threads are using it.
16
+ x += a[0] + a[2];
17
18
+ let _s = format!("hello from the main thread");
19
20
21
+ // After the scope, we can modify and access our variables again:
22
+ a.push(4);
23
+ assert_eq!(x, a.len());
24
+}
0 commit comments