Skip to content

Is Environment.ProcessorCount supposed to be cached? #17976

@jamesqo

Description

@jamesqo

I noticed that dotnet/corefx#9851 which adds Environment to this repo seems to cache ProcessorCount, whereas the 'old' implementation in CoreCLR always seems to do a native call. Is this new implementation really correct?

For example, there is a class in CoreCLR, PlatformHelper, with a static ProcessorCount property that is just a wrapper over Environment.ProcessorCount except that it only updates every 30 seconds. This would imply that 2 different invocations of the method could return different values, right?

Looking at the documentation on MSDN seems to confirm this:

If the current machine contains multiple processor groups, this property returns the number of logical processors that are available for use by the common language runtime (CLR).

That seems to be saying that if there are logical processors on the machine not available to the CLR then they won't be included in the count, and later if they're made available they will be?

cc @stephentoub @jkotas

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions