Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
How do you get the number of available system threads inside a Nim proggram?
Reply
Yes, that returns the number of available threads, though its doc says processors/cores.
Reply
The docs are correct, there is no such thing as the "number of available threads", threads are dynamic in nature, on some
OSes you can create thousands of them.
Reply
Yes, that is what I meant, the threads that are available per system ﴾all cpu cores﴿, which you can see using commands
such as lscpu or htop .
Reply
Nim
proc cpu_count_logical*(): int =
## Return the number of logical CPUs in the system.
try:
return sysconf( SC_NPROCESSORS_ONLN )
except ValueError:
# as a second fallback we try to parse /proc/cpuinfo
for line in lines(PROCFS_PATH / "cpuinfo"):
if line.toLowerAscii().startswith("processor"):
result += 1
return result
I haven't implemented the windows side yet, but take a look here for similar C code.
Reply
8 MONTHS SINCE LAST REPLY
Reply