Opened 8 years ago

Closed 5 years ago

#7916 closed enhancement (fixed)

C++11 thread support is broken.

Reported by: diger Owned by: korli
Priority: normal Milestone: R1
Component: Build System Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All


hrev42598 gcc4

Eiskalt DC++ compilation reportedly fails due to std::mutex

/boot/develop/abi/x86/gcc4/tools/gcc-4.5.3-haiku-110620/lib/gcc/i586-pc-haiku/4.5.3/../../../../include/c++/4.5.3/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
test.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type
test.cpp: In function 'void thread_func1()':

Haiku gcc4 have not support std::mutex How-To-Repeat:

C++ compile the following test case:

#include <vector>
#include <mutex>
#include <thread>

std::vector<int> x;
std::mutex mutex;

void thread_func1()
void thread_func2()

int main()
 std::thread th1(thread_func1);
 std::thread th2(thread_func2);


Change History (6)

comment:1 Changed 8 years ago by bonefish

Owner: changed from bonefish to nobody
Status: newassigned
Type: bugenhancement
Version: R1/alpha3R1/Development

comment:2 Changed 5 years ago by pulkomandy

Summary: mutex compiler support in gcc 4.5.3C++11 thread support is broken.

With gcc4.8, the support for this was enabled. Compile with:

g++-x86 --std=c++11

The resulting binary raises an exception, however ( gcc_x86-4.8.2_2014_01_28-2-x86_gcc2.hpkg / hrev46961).

Here is another test case:

#include <thread>
#include <stdio.h>

int main(void)
        std::thread::id t1 = std::thread::id();
        std::thread::id t2 = std::thread::id();

        printf("%s\n", t1 == t2 ? "PASS" : "FAIL");

According to, operator== should return true when comparing two uninitialized thread ids.

comment:3 Changed 5 years ago by pulkomandy

Owner: changed from nobody to korli

comment:4 Changed 5 years ago by hamish

That test fails because our pthread_equal returns false if either pthread_t is NULL (both are NULL in this case). Other systems with pointer pthread_t types (FreeBSD, possibly others) don't bother with the NULL check.

Not convinced the first test case is valid. If thread 2 runs first it pops from an empty list.

comment:5 Changed 5 years ago by pulkomandy

I don't know about the first test case. For the second one, C++11 says uninitialized thread ids should compare equal. pthread_equal leaves this case 'undefined' in POSIX (

So, this would be a bug in the gthread library used by gcc?

comment:6 Changed 5 years ago by pulkomandy

Resolution: fixed
Status: assignedclosed

In hrev47000 I modified our pthread_equal to compare two NULL thread ids equal. This solves my issue. The initial problem is gone too, as compiling the program works, and it even runs without crashing (wether it makes sense or not is another problem...)

Note: See TracTickets for help on using tickets.