-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add num_cpus to System module #4449
Conversation
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Resolves #4226 Wanted to minimize conditional logic or using flags. |
Maybe a more explicit naming? |
Sure, open to suggestions. |
|
I find the "cpu" terminology quite confusing, as it's actually the maximum number of concurrent threads the hardware can process at the same time - multicore and hyperthreading abstracts |
Maybe |
Should we plan for big.LITTLE core flags too? Maybe in a separate PR? |
Options |
A quick and dirty research on other langs:
|
It seems that |
It looks like |
And if that's the choice then cpu > processors |
src/system.cr
Outdated
@@ -18,4 +18,13 @@ module System | |||
{len, len} | |||
end | |||
end | |||
|
|||
# Returns number of online CPUs |
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.
May I suggest that we further detail what this method does? The current explanation will force anyone who doesn't know the exact meaning of "online CPUs" to review the LibC
documentation. Ideally it'd be nice if we can save them the leap. I checked the docs in some other langs and they seem to use something like "number of [CPUs | Cores | Processors] available to the [program | process | runtime]"
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.
Certainly!
I like calling them logical processors - it makes it clear what the number represents - but it might be too verbose. |
Thanks for the feedback everyone! I've added a commit incorporating the name change and docs update. |
src/system.cr
Outdated
@@ -18,4 +18,13 @@ module System | |||
{len, len} | |||
end | |||
end | |||
|
|||
# Returns the number of processors which are currently online (i.e., available). |
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.
"Returns the number of logical processors available to the system"?
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.
@miketheman just apply @RX14's suggestion and I'll merge this :).
As part of code review, update the name to be more in line with the functionality provided, as well as update the initial docs. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
e25e103
to
0b276be
Compare
@RX14 @mverzilli Done! |
Thanks @miketheman for the contribution and everyone else for reviewing ❤️ |
Signed-off-by: Mike Fiedler miketheman@gmail.com