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

idea: lockfree? #58

Closed
ghost opened this issue Oct 12, 2021 · 3 comments
Closed

idea: lockfree? #58

ghost opened this issue Oct 12, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 12, 2021

Hi,

Any reason to have done a mutex + cond. variable manually?

Is there a rationale why you didn't go lockfree with (yes, possibly a mutex on linux) std::atomic::wait?
I think I will dive into that. But before I do, I would like to hear from you/anyone on that matter.

I am just too lazy to fork TBH.

Thanks

@David-Haim
Copy link
Owner

Can you point out which class are you referring?
Some functions in concurrencpp are pure lock free, most functions are hybrid, some functions use locks.
Lock free doesn't necessarily mean "faster" especially if the code in question is not in a hot path.

@ghost
Copy link
Author

ghost commented Oct 12, 2021

Sure!
your worker_thread_executor, thread_pool etc..

I will find the time to modify the code to be completely lock free, but on Linux and using gcc 11.
Then I will sanitize and compare to see if perf is better.

Action.

@David-Haim
Copy link
Owner

Re-implementing the threadpool executor with a lock-free algorithm won't have any effect.
The threadpool prevents contention by doing 2 things:
non threadpool threads are spread across threadpool-workers using the enqueue algorithm.
threadpool-threads enqueue tasks to a private queue, which doesn't need any synchronization at all.
So there is no lock-contention to begin with, and no real benefit of writing a lock free version of it.

If you have interesting benchmarks with a lock-free version of concurrencpp executors, feel free to share them in the PR and I will surely look at them.

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

1 participant