Compilation aborted - Core Dumped with juce_vst3_helper and std::thread on Linux GCC 9.4.0

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

With CMakeFiles/SpectralRemix_VST3.dir/build.make:221: ./juce_vst3_helper -create -version 1.3.0 -path "../SpectralRemix_artefacts/Debug/VST3/ASAP Spectral Remix.vst3" -output "../SpectralRemix_artefacts/Debug/VST3/ASAP Spectral Remix.vst3/Contents/Resources/moduleinfo.json"

Both juce_vst3_helper and the plugin seem well linked with pthread. I don’t know what could be the problem.

I can catch the error in my code but ideally, it would be better if the plugin could launch the thread.

Tested on the develop branch: Docs: Avoid generating docs for specialisations of SerialisationTraits · juce-framework/JUCE@770d84b · GitHub.

-- 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?

Hello Tom,

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 :sweat_smile: and so far it was compiling fine.

I tried with gcc-10 (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0 and I still have the same issue.

What version of CMake are you using?

I’ve just created a fresh Ubuntu 20.04.6 LTS.

I installed g++, CMake (3.27.6), ninja-build, and all the other JUCE dependencies from here: https://github.com/juce-framework/JUCE/blob/develop/docs/Linux%20Dependencies.md

My configure now looks like yours:

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;

with

inline void addOne (int input, int& output)
{
    output = input + 1;
}

defined just above in the same header file.

Building:

cmake --build ../workspace/build_linux/ -v --target AudioPluginDemo
... Lots of build output here ...
JUCE v7.0.7
4
8

Could you please try the same on your system?

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 :sweat_smile:. But if you want to explore this issue further and need more information, let me know.

I just came to the same conclusion. Here’s a much older bug report that points at GCC: Bug #1228201 “g++ doesn't compile simple code, using thread head...” : Bugs : gcc-defaults package : Ubuntu

Another solution is to add -Wl,--no-as-needed.

Or any version of clang++ works as expected.

1 Like