-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WaitCondition in JACK backend mixes up two clocks #795
Comments
Can you give references to the relevant source code functions and line numbers please? Is this timeout time-critical? If it's some kind of high-precision scheduling timeout then that is different than if it is just a slow last-ditch timeout.
Is |
portaudio/src/hostapi/jack/pa_jack.c Line 1058 in 68e963a
The timeout is a 10 minute last ditch timeout.
Since pa_win_hostapis.c contains an #if PA_USE_JACK line, I'd say no. But then the question is, why does Windows have pthread_cond_timedwait? It is also not supported before macOS 10.12 (released in 2016). Linux gained support in 2003. Here they list a few other UNIXes: https://www.rubydoc.info/stdlib/core/Process.clock_gettime If
gettimeofday has been around forever. POSIX.1-2008 marked it as deprecated in favor of clock_gettime, but everyone still supports it. |
Thanks. It sounds like CLOCK_MONOTONIC provides the more robust solution when it's available.
I think you need to link with a Windows pthread library. I seem to remember that being discussed. I've never tried JACK on Windows myself. I guess that means that this same bug exists on Windows (?and Macintosh), since FWIW here's a Windows implementation of https://stackoverflow.com/questions/10905892/equivalent-of-gettimeofday-for-windows |
On Linux, https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html Seems like there are three things here:
We should add a caveat to |
…k is required. try to stop PortAudio#795 happening again
* Ensure that the clock that is configured on the cond var object is the one that is used to compute the wait deadline. * Ensure that the most appropriate clock is selected on each platform based on availability CLOCK_BOOTTIME > CLOCK_MONOTONIC > CLOCK_REALTIME (on Mac use gettimeofday because other clock interfaces are either not available or broken). NB: use GetSystemTimeAsFileTime on Windows. should be much faster than GetSystemTime+SystemTimeToFileTime according to http://www.windowstimestamp.com/description. thanks s09bQ5 Used directly or indirectly by pa_jack, pa_alsa, pa_asihpi Resolves #795, #807.
Describe the bug
WaitCondition in
src/hostapi/jack/pa_jack.c
usesPaUtil_GetTime
to calculate a timeout and then uses that timeout value withpthread_cond_timedwait
. By default the timeouts passed topthread_cond_timedwait
must be based onCLOCK_REALTIME
.PaUtil_GetTime
on the other hand prefers to useCLOCK_MONOTONIC
.Usually
CLOCK_MONOTONIC
is much smaller thanCLOCK_REALTIME
so thatpthread_cond_timedwait
will timeout immediately.To Reproduce
Expected behavior
It should work
Actual behavior
It doesn't work
Desktop (please complete the following information):
Additional context
I see three solutions:
clock_gettime(CLOCK_REALTIME, &ts)
instead ofPaUtil_GetTime
. It also simplifies the code because we don't have to convert fromPaTime
back tostruct timespec
. The drawback is the one that led to the introduction ofCLOCK_MONOTONIC
: It won't work if someone changes the time significantly while we are waiting.pthread_condattr_setclock
. This is available since IEEE 1003.1j-2000. A bit more code is needed (pthread_condattr_init
/pthread_condattr_destroy
).pthread_cond_clockwait
. Available since Glibc 2.30 (released in 2019) but not every platform with JACK uses Glibc.The text was updated successfully, but these errors were encountered: