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

Investigate use of std::atomic_flag instead of std::binary_semaphore #42

Open
DeveloperPaul123 opened this issue Jul 3, 2023 · 2 comments

Comments

@DeveloperPaul123
Copy link
Owner

std::atomic_flag is the only atomic primitive guaranteed to be lock free. It would be interesting to see if this has any positive impact on performance over std::binary_semaphore.

@DeveloperPaul123
Copy link
Owner Author

DeveloperPaul123 commented Jul 3, 2023

Did a quick benchmark on quick-bench and it seems that std::binary_semaphore has the best performance when it comes to ping/pong which I think matches well with how we're using it in the thread pool (as a signal mechanism).

https://quick-bench.com/q/JkZjpTgsjQkSiyI20IRcZtEFNso

JkZjpTgsjQkSiyI20IRcZtEFNso

@DeveloperPaul123
Copy link
Owner Author

I wrote a quick benchmark and ran it locally on windows and am getting inconsistent results. I think I will need to do a more proper test with pyperf on a Linux machine to get better numbers.

relative ms/op op/s err% total Thread signaling
100.0% 451.75 2.21 1.8% 53.95 std::atomic_flag
99.2% 455.40 2.20 2.0% 54.42 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 444.76 2.25 2.1% 53.20 std::atomic_flag
98.4% 452.16 2.21 3.0% 53.78 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 485.05 2.06 0.3% 57.51 std::atomic_flag
103.0% 470.99 2.12 0.8% 57.44 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 457.13 2.19 1.9% 55.43 std::atomic_flag
96.9% 471.90 2.12 3.8% 56.81 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 481.77 2.08 2.8% 56.86 std::atomic_flag
105.2% 457.91 2.18 4.1% 54.98 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 465.74 2.15 0.4% 55.85 std::atomic_flag
101.3% 459.84 2.17 0.6% 55.00 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 453.31 2.21 0.9% 54.72 std::atomic_flag
95.0% 477.07 2.10 2.4% 56.92 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 477.71 2.09 0.8% 57.59 std::atomic_flag
101.6% 470.13 2.13 0.6% 56.57 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 477.80 2.09 1.1% 57.12 std::atomic_flag
100.4% 475.79 2.10 1.8% 56.92 std::binary_semaphore
relative ms/op op/s err% total Thread signaling
100.0% 479.51 2.09 1.2% 58.10 std::atomic_flag
102.9% 465.78 2.15 4.3% 55.52 std::binary_semaphore

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