2014-03-01 43 views
2
// 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; 
} 

從教程和其他許多示例中,我得到了以下錯誤。boost線程pthread_mutex_lock問題

enter image description here

我對OS X 10.8.2的Xcode 4.6.2,安裝升壓1.54使用sudo端口和連接所有的標題搜索路徑和庫,並添加了dylibs。有人能告訴我什麼是問題。如果沒有連接,它有時會與文本「hello world」和「sdfsfsd」穿插,因爲它沒有等待線程完成,但有時也會給我這個錯誤。謝謝!

回答

0

線程必須被接合(或脫離,這個)程序終止

之前從docs

析構函數V2

當表示一個線程線程對象如果線程爲可連接,程序將被終止。

+0

right我的意思是加入它總是會產生錯誤 – tabrisz

+0

什麼是錯誤?我看到一個處於break模式的調試器。並且有更多的線程不僅僅是你產生的線程 – sehe

+0

我是xcode的新手,不熟悉調試器。它不是打印std :: cout <<「sdfsfsd」<< endl;基本上。只是掛在屏幕上 – tabrisz