//需要使用-lboost_thread链接thread库
#include "boost/thread/mutex.hpp"
#include "boost/thread/thread.hpp"
#include "boost/thread/lock_guard.hpp"
#include <iostream>
using namespace std;
using namespace boost;
class A
{
public:
static void print(std::string s)
{
boost::unique_lock<boost::mutex> lock(mutex_);
for (int j = 0;j<10;++j)
{
cout << ++i <<endl;
}
}
protected:
private:
static boost::mutex mutex_;
static int i;
};
int A::i = 0;
boost::mutex A::mutex_;
int main()
{
boost::thread t1(A::print,"hello world");
t1.join();
return 0;
}