Skip to content

Conversation

DavidPL1
Copy link

@DavidPL1 DavidPL1 commented Jul 14, 2025

Using a thread pool with $n > 1$ workers substantially raises the CPU usage. This is mainly due to the worker queue using std::this_thread::yield right here.
Especially in a nearly idle simulation state (e.g. when pausing in Simulate-like programs), this unnecessarily increases CPU load with $n$ cores at 100% load.

My proposed solution is to introduce an option to toggle busy waiting, which would opt for std::this_thread::sleep if disabled. This would retain the option to use yield instead of sleep if speed is more important. Although, I think that sleeping should be the default fit for most use cases.

Let me know your thoughts on this

@DavidPL1 DavidPL1 marked this pull request as ready for review August 14, 2025 07:36
@DavidPL1 DavidPL1 force-pushed the adds-mjthread-busywait-opt branch from 226260f to 8da4bcf Compare August 14, 2025 07:38
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.

1 participant