简体   繁体   中英

boost thread pthread_mutex_lock issue

// 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;
}

Taken from the tutorials and along with many other examples, I've gotten the following error.

在此处输入图片说明

I'm on xcode 4.6.2 on OS X 10.8.2, installed boost 1.54 with sudo port and linked all the header search paths and libraries and added the dylibs. Can someone tell me what's the issue. Without the join, it works sometimes with the text "hello world" and "sdfsfsd" interspersed since it's not waiting for the thread to finish but sometimes gives me this error as well. Thanks!

Threads must be joined (or detached, IIRC) before program termination

From the docs :

Destructor V2

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM