Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set bounded number lower task numbers will cause problem #2

Open
whtgg opened this issue Jan 2, 2024 · 1 comment
Open

set bounded number lower task numbers will cause problem #2

whtgg opened this issue Jan 2, 2024 · 1 comment

Comments

@whtgg
Copy link

whtgg commented Jan 2, 2024

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);

@divi255
Copy link
Member

divi255 commented Jan 2, 2024

Good day,

I tested the example, the behaviour looks fine. Could you please explain where the problem is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants