Home >Backend Development >C++ >Why Does g Still Throw \'Enable Multithreading to use std::thread: Operation not permitted\' Even With -pthread Flag?

Why Does g Still Throw \'Enable Multithreading to use std::thread: Operation not permitted\' Even With -pthread Flag?

Barbara Streisand
Barbara StreisandOriginal
2024-10-31 12:46:18429browse

Why Does g   Still Throw

Compiling Multithread Code with g

An individual encountered difficulty compiling multithread code using g , despite specifying the necessary flags. The code, which includes header files for I/O and thread manipulation, was straightforward, containing a worker thread and a main thread. However, the compilation attempt resulted in an error:

terminate called after throwing an instance of 'std::system_error'   
what():  Enable multithreading to use std::thread: Operation not permitted  
Aborted (core dumped)

The individual had already included the -pthread flag in their compilation command, which is typically recommended to enable multithreading in g . However, the issue persisted.

The answer to the problem stems from a bug in gcc. The workaround suggested in the last comment of the relevant bug discussion involves adding the following flag to the compilation command:

-Wl,--no-as-needed

By implementing this workaround, the individual was able to successfully compile and run their multithread code using g .

The above is the detailed content of Why Does g Still Throw \'Enable Multithreading to use std::thread: Operation not permitted\' Even With -pthread Flag?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn