相关疑难解决方法(0)

cout同步/线程安全吗?

一般来说,我假设流不同步,由用户做适当的锁定.但是,做cout标准库中的特殊处理吗?

也就是说,如果多个线程正在写入,cout它们会破坏cout对象吗?据我所知,即使同步,你仍然会得到随机交错的输出,但保证交错.也就是说,cout从多个线程使用是否安全?

该供应商是否依赖?gcc做什么?


重要提示:如果您说"是",请为您的答案提供某种参考,因为我需要某种证明.

我关注的还不是基础系统调用,这些都很好,但是流在顶部添加了一层缓冲.

c++ gcc c++11

108
推荐指数
4
解决办法
4万
查看次数

std :: thread错误(线程不是std的成员)

我使用macports编译并安装了gcc4.4.

当我尝试使用 - > g ++ -g -Wall -ansi -pthread -std = c ++ 0x main.cpp ...进行编译时:

 #include <thread>
 ...
  std::thread t(handle);
  t.join();
 ....
Run Code Online (Sandbox Code Playgroud)

编译器返回:

 cserver.cpp: In member function 'int CServer::run()':
 cserver.cpp:48: error: 'thread' is not a member of 'std'
 cserver.cpp:48: error: expected ';' before 't'
 cserver.cpp:49: error: 't' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

std::cout <<...编译好..

谁能帮我?

c++ multithreading gcc std c++11

23
推荐指数
3
解决办法
4万
查看次数

编译代码块中的线程程序时出错

我的线程程序是:

#include<iostream>
#include<thread>
using namespace std;

void t()
{
    cout<<"from thread\n";
}

int main()
{
     thread i(&t);
     cout <<"from main\n";
     i.join();
}
Run Code Online (Sandbox Code Playgroud)

但它在代码块中显示以下错误:

1)'thread ' was not declared in this scope
2)expected ';' before 'i'
3)'i' was not declared in this scope 
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我正在使用Windows和代码块12.11

c++ codeblocks

1
推荐指数
1
解决办法
3437
查看次数

标签 统计

c++ ×3

c++11 ×2

gcc ×2

codeblocks ×1

multithreading ×1

std ×1