Excessive CPU usage due to multi-threading
Martin Guy <[email protected]> Thu, 26 Feb 2026 13:44:50 +0100
| Newsgroups | gmane.comp.audio.sox |
|---|---|
| Message-ID | <CAL4-wQpLGd6xGxAmgnFywNGcbNaeB+kwU=XG9U69zHRCC=sFOQ@mail.gmail.com> |
Hi
A relatively serious defect is being reported in sox_ng-14.6 and 14.7
whereby, due to me changing the default from --single-threaded to
--multithreaded, SoX can become incredibly slow: in one case
increasing the wallclock time from 0.38 seconds to 7m23s and in
another from 5 seconds to 210.
The cause is that when two OpenMP threads need the same resource
by default they busy-wait for a while ("spinning") before going to sleep
and waiting to be woken up. Bad OpenMP.
The workarounds are to include --single-threaded as an option
(or set SOX_OPTS=--single-threaded) or to set the environment
variable OMP_WAIT_POLICY=PASSIVE before launching SoX
to make it use multiple processors efficiently.
We are still figuring out what the best solution to this can be;
at worst we can revert to only using one processor by default.
Thanks to danadam for finding the cause and workarounds for this.
Expect another slew of patch releases soon ;-/
M
Cheers, Dr. TM