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
Use atomic counters #25
Conversation
The massive test fails on travic-ci in debug mode because the |
@@ -221,7 +224,7 @@ mod test { | |||
} | |||
}); | |||
} | |||
sleep_ms(1000); | |||
sleep_ms(1024); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did these change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it down to 10ms, but it was broken on some machines. then I choos a geeky number.
Looks great! Can you rebase and squash? |
@@ -54,7 +55,8 @@ impl<'a> Sentinel<'a> { | |||
impl<'a> Drop for Sentinel<'a> { | |||
fn drop(&mut self) { | |||
if self.active { | |||
*self.thread_counter.write().unwrap() -= 1; | |||
// TODO check return value and loop | |||
(*self.thread_counter).fetch_sub(1, Ordering::SeqCst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think *
is needed.
- choose geeky numbers for tests - Add a new Test for massive task creation - Add new test for shrinking the pool - Let the test wait with a barrier not with a machine dependant sleep.
Rebased into one commit. Thank you for the review. |
pub fn set_threads(&mut self, threads: usize) { | ||
assert!(threads >= 1); | ||
let current_max = self.max_count.lock().unwrap().clone(); | ||
*self.max_count.lock().unwrap() = threads; | ||
let current_max = (*self.max_count).swap(threads, Ordering::Release); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*
here can be omitted too.
Thanks for your contribution! 🎉 |
Version 1.0.2 has been released which includes these changes. |
Thank you, was a pleasure. |
I tried making the pool faster on NUMA systems but the effect is very minor, because the channel uses a Mutex.
However, since I already did the work, I would like to share it.
Should I rebase the history into one commit?