This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std thread,mutex,cv and static linking with GCC


Hi,

I was getting random crashes when using thread, mutex, and cv and statically linking my project. Some of the libraries I link against use pthread, so I narrowed the issue down to this test:

I statically link a simple test that uses thread, mutex, and cv like this: "g++ --std=c++11 -pthread -static test.cc" and  I get this when I run it:

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

Everything works fine if I don't use -static, the problem is specific to static linking. If in my test I use pthread directly to create a thread, then it runs and creating an std::thread also works, but the test crashes when using the cv. My theory is that the linker is being lazy (weak references? optimization?) and the pthread stuff std needs is not included in the binary unless referenced somewhere else. In real projects this is quite dangerous because having dependencies that use most of the pthread stuff makes these crashes rare (I caught this problem with a stress test).

Any ideas? Is this s bug in the library?

Thanks,
Damian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]