Skip to content

pipewire-jack: fix use of `pthread_cancel`

Jef requested to merge Vurich/pipewire:pipewire-jack-thread-cancellation into master

pthread_cancel is always undefined behavior when used on arbitrary user code, and JACK clients are not written with it in mind. Thread cancellation should be opt-in rather than always-on, and so for the JACK shim it makes the most sense for the default mode to be joining the process thread (like in JACK and JACK2) and for hard-killing the thread to be a separate function that the library consumer must use explicitly - and only if they can prove that anything running on the process thread is sound to hard-kill.

We ran into this in our project because we submitted jobs to a threadpool inside the process function, and the jobs referenced data on the stack of the process function. When the process function was cancelled those stack frames were destroyed and the in-progress jobs then segfaulted. While doing multithreading inside a process callback is a non-traditional usecase, it is a valid usecase and one that works just fine with JACK and JACK2.

Merge request reports