Home > Article > Backend Development > Why Does My C Multithreaded Program Throw an \"Operation Not Permitted\" Error Despite Using \'-pthread\'?
Problem:
Despite using the recommended '-pthread' flag, you encounter a runtime error when attempting to compile and execute a multithreaded C program with g . The error message indicates "Operation not permitted" when attempting to use the 'std::thread' object.
Possible Solution:
The issue may be due to a bug in the g compiler. To resolve this, apply the following workaround:
Append the '-Wl,--no-as-needed' flag to the compilation command. This flag instructs the linker to not consider the symbol 'pthreads' as needed for the program.
Revised Compilation Command:
g++ main.cpp -o main.out -pthread -std=c++11 -Wl,--no-as-needed
This workaround should allow you to compile and execute your multithreaded code successfully.
Note:
This issue has been reported on the official g bug tracker, and a fix is expected in the future. However, the workaround provided here should resolve the problem for now.
The above is the detailed content of Why Does My C Multithreaded Program Throw an \"Operation Not Permitted\" Error Despite Using \'-pthread\'?. For more information, please follow other related articles on the PHP Chinese website!