Feature request: Change the behavior when `-j` is `0`
sorairolake opened this issue · comments
-T
of xz
and zstd
uses as many worker threads as there are physical CPU cores when the value is 0
. So, I propose that -j
behaves similarly to these.
bzip3 -j 0 README.md
# equivalent to
bzip3 -j "$(nproc)" README.md
We want a C analogue of std::thread::hardware_concurrency()
. Maybe determine the amount of CPUs by task affinity (sched_getaffinity
- Linux-specific), sysconf
(GNU-only), get_nprocs
(also GNU), or maybe read /proc/cpuinfo
... Another possibility is pthread_getaffinity_np
, or NetBSD 5+ GNU's sched_getaffinity_np
, on Windows we would want GetProcessAffinityMask
. In practice, the sysconf
appears to work on glibc, Mac OS X 10.5, FreeBSD, AIX, OSF/1, Solaris, Cygwin, Haiku. HP-UX would require pstat_getdynamic
, IRIX uses sysmp
; as a fallback on Windows platforms we could use GetSystemInfo
. I will look into it.