getAvailableProcessors

Native
1.3
@ExperimentalStdlibApi fun getAvailableProcessors(): Int
(source)

The number of logical processors available.

Can be not equal to the number of processors in the system if some restrictions on processor usage were successfully detected. Some kinds of processor usage restrictions are not detected, for now, e.g., CPU quotas in containers.

The value is computed on each usage. It can change if some OS scheduler API restricts the process during runtime. Also, value can differ on different threads if some thread-specific scheduler API was used.

If one considers the value to be inaccurate and wants another one to be used, it can be overridden by KOTLIN_NATIVE_AVAILABLE_PROCESSORS environment variable. When the variable is set and contains a value that is not positive Int, IllegalStateException will be thrown.