Home > Backend Development > C++ > Why Does My Multithreaded Code Still Throw \'std::system_error\' Even With \'-pthread\'?

Why Does My Multithreaded Code Still Throw \'std::system_error\' Even With \'-pthread\'?

Susan Sarandon
Release: 2024-11-02 09:29:31
Original
307 people have browsed it

Why Does My Multithreaded Code Still Throw 'std::system_error' Even With '-pthread'?

Compiling Multithreaded Code with g : 'std::system_error' Resolved

Encountering the error 'std::system_error' while compiling multithreaded code with g can be frustrating. Despite explicitly specifying the '-pthread' flag, the issue persists.

Investigating the provided code, there doesn't seem to be any apparent problem. However, the issue arises from a bug in gcc. The workaround provided by a member of the SO C chat offers a solution:

-Wl,--no-as-needed
Copy after login

When added to the compilation command, this flag resolves the issue, allowing the multithreaded code to compile and run successfully. The updated compilation command would be:

$ g++ main.cpp -o main.out -pthread -std=c++11 -Wl,--no-as-needed
Copy after login

The above is the detailed content of Why Does My Multithreaded Code Still Throw \'std::system_error\' Even With \'-pthread\'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template