MCPcopy Create free account
hub / github.com/SSheldon/rust-dispatch / test_barrier_sync

Function test_barrier_sync

src/queue.rs:441–463  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

439
440 #[test]
441 fn test_barrier_sync() {
442 let q = Queue::create("", QueueAttribute::Concurrent);
443 let num = Arc::new(Mutex::new(0));
444
445 async_increment(&q, &num);
446 async_increment(&q, &num);
447
448 let num2 = num.clone();
449 let result = q.barrier_sync(move || {
450 let mut num = num2.lock().unwrap();
451 if *num == 2 {
452 *num = 10;
453 }
454 *num
455 });
456 assert_eq!(result, 10);
457
458 async_increment(&q, &num);
459 async_increment(&q, &num);
460
461 q.barrier_sync(|| ());
462 assert_eq!(*num.lock().unwrap(), 12);
463 }
464
465 #[test]
466 fn test_barrier_async() {

Callers

nothing calls this directly

Calls 3

barrier_syncMethod · 0.80
async_incrementFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected