c++0x std::lock undefined reference

I'm learning c++0x threading library and I tried to use std::lock function. When I'm compiling the following code with

g++ -std=c++0x -pthread source.cpp (also I've tried with -lpthread, it doesn't matter, result is the same)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <thread>
#include <mutex>

using namespace std;

mutex m, m2;

void hello()
{
	lock(m, m2);
	cout<<"hello"<<endl;
	m.unlock();
	m2.unlock();
}

int main()
{
	thread t(hello);
	t.join();
	return 0;
}


I'm getting
1
2
3
/tmp/ccFjlkVB.o: In function `hello()':
test2.cpp:(.text+0xfe): undefined reference to `_ZSt4lockISt5mutexS0_IEEvRT_RT0_DpRT1_'
collect2: ld returned 1 exit status


Everything works fine without std::lock (for example using std::lock_guard or simply m.lock(); m2.lock(), but the point of using std::lock is chance to avoid potential deadlock).
Topic archived. No new replies allowed.