Opened 13 years ago

Closed 11 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:
Platform: All

Description

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()
{
 mutex.lock();
 x.push_back(0);
 mutex.unlock();
}
void thread_func2()
{
 mutex.lock();
 x.pop_back();
 mutex.unlock();
}

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

 th1.join();
 th2.join();
}

Change History (6)

comment:1 by bonefish, 13 years ago

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

comment:2 by pulkomandy, 11 years ago

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 http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp, operator== should return true when comparing two uninitialized thread ids.

comment:3 by pulkomandy, 11 years ago

Owner: changed from nobody to korli

comment:4 by hamish, 11 years ago

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 by pulkomandy, 11 years ago

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 (http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html).

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

comment:6 by pulkomandy, 11 years ago

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.