Open whtgg opened 10 months ago
let pool = Pool::bounded(3); let counter = Arc::new(AtomicUsize::new(0)); for _ in 1..=5 { let counter_c = counter.clone(); pool.spawn(async move { sleep(Duration::from_secs(3)).await; counter_c.fetch_add(1, Ordering::SeqCst); }) .await .unwrap(); } sleep(Duration::from_secs(3)).await; // println!("{}",counter.load(Ordering::SeqCst)); assert_eq!(counter.load(Ordering::SeqCst), 5);
Good day,
I tested the example, the behaviour looks fine. Could you please explain where the problem is?
let pool = Pool::bounded(3); let counter = Arc::new(AtomicUsize::new(0)); for _ in 1..=5 { let counter_c = counter.clone(); pool.spawn(async move { sleep(Duration::from_secs(3)).await; counter_c.fetch_add(1, Ordering::SeqCst); }) .await .unwrap(); } sleep(Duration::from_secs(3)).await; // println!("{}",counter.load(Ordering::SeqCst)); assert_eq!(counter.load(Ordering::SeqCst), 5);