MCPcopy Create free account
hub / github.com/NthTensor/Forte / scope_concurrency

Function scope_concurrency

src/scope.rs:1176–1202  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1174 static THREAD_POOL: ThreadPool = ThreadPool::new();
1175 THREAD_POOL.resize_to_available();
1176
1177 let mut string = "a";
1178 THREAD_POOL.scope(|scope| {
1179 scope.spawn(|_: &Worker| {
1180 string = "b";
1181 });
1182 });
1183 assert_eq!(string, "b");
1184
1185 THREAD_POOL.depopulate();
1186 }
1187
1188 /// Test that it is possible to borrow local data immutably within deeply
1189 /// nested scopes. This is also mostly here to ensure stuff like this
1190 /// compiles.
1191 #[test]
1192 fn scope_borrow_twice() {
1193 static THREAD_POOL: ThreadPool = ThreadPool::new();
1194 THREAD_POOL.resize_to_available();
1195
1196 let counter = AtomicU8::new(0);
1197 THREAD_POOL.scope(|scope| {
1198 scope.spawn(|_: &Worker| {
1199 counter.fetch_add(1, Ordering::Relaxed);
1200 scope.spawn(|_: &Worker| {
1201 counter.fetch_add(1, Ordering::Relaxed);
1202 });
1203 });
1204 scope.spawn(|_: &Worker| {
1205 counter.fetch_add(1, Ordering::Relaxed);

Callers

nothing calls this directly

Calls 6

scopeFunction · 0.85
resize_to_availableMethod · 0.80
with_workerMethod · 0.80
joinMethod · 0.80
depopulateMethod · 0.80
spawnMethod · 0.45

Tested by

no test coverage detected