My plugin launches a std::thread in its constructor and it seems not to be supported when running the plugin with juce_vst3_helper on Linux. It generates a std::system_error what(): Enable multithreading to use std::thread: Operation not permitted.
terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
make[2]: *** [CMakeFiles/SpectralRemix_VST3.dir/build.make:221 : SpectralRemix_artefacts/Debug/VST3/ASAP Spectral Remix.vst3/Contents/x86_64-linux/ASAP Spectral Remix.so] Erreur 134
make[2]: *** Suppression du fichier « SpectralRemix_artefacts/Debug/VST3/ASAP Spectral Remix.vst3/Contents/x86_64-linux/ASAP Spectral Remix.so »
make[1]: *** [CMakeFiles/Makefile2:382 : CMakeFiles/SpectralRemix_VST3.dir/all] Erreur 2
make: *** [Makefile:146 : all] Erreur 2
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
...
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
I’ve just tried the same using GCC 9.5.0, but don’t run into the problem. The other difference I have is CMAKE_HAVE_LIBC_PTHREAD - Success when configuring.
What operating system are you using, and what libc?
Ubuntu 20.04.6 LTS
ldd (Ubuntu GLIBC 2.31-0ubuntu9.9) 2.31
GCC 9.4.0 is the default version of this OS (using apt) but I can try to install GCC 9.5.0. But on Linux I’m always a bit scared that updating the compilation tools breaks the support with some distributions and so far it was compiling fine.
cmake . -B ../workspace/build_linux -Werror=dev -GNinja -DCMAKE_BUILD_TYPE=Debug -DJUCE_BUILD_EXAMPLES=1 -DCMAKE_CXX_FLAGS=-Werror
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'alsa'
-- Found alsa, version 1.2.2
-- Checking for module 'freetype2'
-- Found freetype2, version 23.1.17
-- Checking for module 'gl'
-- Found gl, version 1.2
-- Checking for module 'libcurl'
-- Found libcurl, version 7.68.0
-- Checking for modules 'webkit2gtk-4.0;gtk+-x11-3.0'
-- Found webkit2gtk-4.0, version 2.38.6
-- Found gtk+-x11-3.0, version 3.24.20
-- Configuring juceaide
-- Building juceaide
-- Exporting juceaide
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done (47.0s)
-- Generating done (3.5s)
-- Build files have been written to: /home/tom/Development/workspace/build_linux
I added this to the AudioProcessor constructor in AudioPluginDemo:
int x, y;
std::thread t1 (addOne, 3, std::ref (x));
std::thread t2 (addOne, 7, std::ref (y));
t1.join();
t2.join();
std::cout << x << std::endl << y << std::endl;
The compilation succeeds but after comparing it with my plugin, it turns out that I use link-time optimisation using CMAKE_INTERPROCEDURAL_OPTIMIZATION. So I tried: cmake . -B ../workspace/build_linux -Werror=dev -GNinja -DCMAKE_BUILD_TYPE=Debug -DJUCE_BUILD_EXAMPLES=1 -DCMAKE_CXX_FLAGS="-Werror -flto -fno-fat-lto-objects"
and it crashes with the same message:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
It seems that juce_vst3_helper doesn’t support LTO with GCC and C++ > 14 (I don’t know why but it seems related to this issue).
I removed CMAKE_INTERPROCEDURAL_OPTIMIZATION and used set_target_properties(MyPlugin PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) instead so LTO only applies to the plugin and it works fine!
I’m having some other issues updating to JUCE 7.0.7 that I need to resolve, so I consider this one resolved . But if you want to explore this issue further and need more information, let me know.