runtime: implement NumCPU for -scheduler=threads

For the threads scheduler, it makes sense to have NumCPU available.
For all other schedulers, the number of available CPUs is practically
limited to one by the scheduler (even though the system might have more
CPUs).
This commit is contained in:
Ayke van Laethem
2025-01-21 11:10:18 +01:00
committed by Ron Evans
parent 25b83920b6
commit 02c5c4213c
9 changed files with 36 additions and 13 deletions
+5
View File
@@ -50,6 +50,11 @@ func Gosched() {
// operation, so is probably best not to use.
}
// NumCPU returns the number of logical CPUs usable by the current process.
func NumCPU() int {
return task.NumCPU()
}
// Separate goroutine (thread) that runs timer callbacks when they expire.
func timerRunner() {
for {