提升线程pthread_mutex_lock问题

时间:2014-03-01 21:13:06

标签: 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并链接了所有标头搜索路径和库并添加了dylib。有人能告诉我这是什么问题。没有连接,它有时会与文本“hello world”和“sdfsfsd”一起散布,因为它不等待线程完成,但有时也会给我这个错误。谢谢!

1 个答案:

答案 0 :(得分:0)

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

来自docs

  

析构函数V2

     

当代表执行线程的boost :: thread对象被销毁时,如果线程可加入,程序将终止。