简单的程序就像这样
#include <iostream> // std::cout
#include <thread> // std::thread
#include <mutex> // std::mutex
std::mutex mtx; // mutex for critical section
int main ()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试以下编译
$ /usr/local/Cellar/gcc46/4.6.4/bin/g++-4.6 -std=gnu++0x -I/usr/local/Cellar/gcc46/4.6.4/gcc/include/c++ -L/usr/local/Cellar/gcc46/4.6.4/gcc/lib temp_mutex.cpp
temp_mutex.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我在Mac上编译.
它对我有用:
$ g++-4.7 -O2 -Wall -std=c++11 -c mutextest.cc
$ g++-4.6 -O2 -Wall -std=c++0x -c mutextest.cc
$ g++-4.6 -O2 -Wall -std=gnu++0x -c mutextest.cc
$ g++-4.4 -O2 -Wall -std=c++0x -c mutextest.cc
$ g++-4.4 -O2 -Wall -std=gnu++0x -c mutextest.cc
Run Code Online (Sandbox Code Playgroud)
这些都没有生成任何错误消息.
| 归档时间: |
|
| 查看次数: |
14714 次 |
| 最近记录: |