c++ - boost 线程 pthread_mutex_lock 问题

标签 c++ xcode boost

// Copyright (C) 2001-2003
// William E. Kempf
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std;

void helloworld()
{
    std::cout << "Hello World!" << std::endl;
}

int main()
{
    boost::thread thrd(&helloworld);
    thrd.join();
    std::cout<<"sdfsfsd"<<endl;
}

根据教程和许多其他示例,我遇到了以下错误。

enter image description here

我在 OS X 10.8.2 上使用 xcode 4.6.2,安装了带 sudo 端口的 boost 1.54,链接了所有 header 搜索路径和库,并添加了动态库。有人能告诉我这是什么问题吗?如果没有连接,它有时会与文本“hello world”和“sdfsfsd”穿插在一起,因为它不等待线程完成但有时也会给我这个错误。谢谢!

最佳答案

线程必须在程序终止前加入(或分离,IIRC)

来自docs :

Destructor V2

When the boost::thread object that represents a thread of execution is destroyed the program terminates if the thread is joinable.

关于c++ - boost 线程 pthread_mutex_lock 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22120452/

相关文章:

objective-c - 数组在 Xcode 4 调试器中显示为空,即使它们不是

python - 错误: no matching function for call to ‘CBNET::CBNET(boost::reference_wrapper<const CBNET>::type&)’

sockets - Boost Asio tcp::iostream构造每秒钟使用都会引发访问冲突异常

c++ - 这样的代码怎么会返回这么乱?

c++ - 编码和读取 ID3 标签

xcode - Bitrise & SPM - 如何使用 Bitrise 构建私有(private) SPM 依赖项?

ios - 分页UIScrollView如何添加多个UIImageView?

c++ - 使用 Qt,如何使用鼠标移动事件向上或向左调整小部件的大小

C++ 字符串小写与自定义语言环境

c++ - 如何调整 FindBoost.cmake 静态库搜索 x32 boost 库?