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

Use atomic counters #25

Merged
merged 1 commit into from May 9, 2016
Merged

Use atomic counters #25

merged 1 commit into from May 9, 2016

Conversation

dns2utf8
Copy link
Member

@dns2utf8 dns2utf8 commented May 8, 2016

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?

@dns2utf8
Copy link
Member Author

dns2utf8 commented May 8, 2016

The massive test fails on travic-ci in debug mode because the iter().take(test_tasks).fold is faster than the last thread finishing itself.
This could happen with any synchronisation method. I adjusted the test accordingly to allow values of 0 and 1.
The test could also wait for some time or not test for the final size.

@@ -221,7 +224,7 @@ mod test {
}
});
}
sleep_ms(1000);
sleep_ms(1024);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these change?

Copy link
Member Author

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.

@frewsxcv
Copy link
Collaborator

frewsxcv commented May 8, 2016

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);
Copy link
Contributor

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.
@dns2utf8
Copy link
Member Author

dns2utf8 commented May 9, 2016

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);
Copy link
Contributor

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.

@frewsxcv
Copy link
Collaborator

frewsxcv commented May 9, 2016

Thanks for your contribution! 🎉

@frewsxcv frewsxcv merged commit 637e9c2 into rust-threadpool:master May 9, 2016
@frewsxcv
Copy link
Collaborator

frewsxcv commented May 9, 2016

Version 1.0.2 has been released which includes these changes.

@dns2utf8 dns2utf8 deleted the atomic branch May 10, 2016 06:55
@dns2utf8
Copy link
Member Author

Thank you, was a pleasure.

@dns2utf8 dns2utf8 restored the atomic branch May 17, 2016 13:30
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

Successfully merging this pull request may close these issues.

None yet

3 participants