#include <iostream>
#include <string>
#include <vector>
#include "ace/OS.h"
#include "boost/thread.hpp"
#include "boost/function.hpp"
#include "boost/bind.hpp"
boost::mutex io_mutex;
void myThreadFunc(void) {
std::cout << "myThreadFunc" << std::endl;
}
struct Counter {
Counter(int i ) :
counter_(i) {
}
void operator()(void) {
for (int i = 0; i < counter_; i++) {
boost::mutex::scoped_lock lock(io_mutex);
std::cout << "i:" << i << "," << ACE_OS::thr_self() << std::endl;
}
}
int counter_;
};
class StaticClass {
public:
static void start() {
boost::thread myThread(&threadFunc);
myThread.join();
}
static void threadFunc(void) {
std::cout << "threadFunc:" << ACE_OS::thr_self() << std::endl;
}
};
class InstanceClass {
public:
void start(void) {
boost::function0<void> f =
boost::bind(&InstanceClass::threadFunc, this);
boost::thread myThread5(f);
myThread5.join();
}
void threadFunc(void) {
std::cout << "threadFunc:Intance," << ACE_OS::thr_self() << std::endl;
}
};
int main(int argc, char * argv[]) {
boost::thread myThread(&myThreadFunc);
myThread.join();
boost::thread myThread2(Counter(5));
myThread2.join();
boost::thread myThread3(Counter(9));
myThread3.join();
StaticClass::start();
InstanceClass instance;
boost::thread mythread6(boost::bind(&InstanceClass::threadFunc, instance));
mythread6.join();
return 0;
}
#include <string>
#include <vector>
#include "ace/OS.h"
#include "boost/thread.hpp"
#include "boost/function.hpp"
#include "boost/bind.hpp"
boost::mutex io_mutex;
void myThreadFunc(void) {
std::cout << "myThreadFunc" << std::endl;
}
struct Counter {
Counter(int i ) :
counter_(i) {
}
void operator()(void) {
for (int i = 0; i < counter_; i++) {
boost::mutex::scoped_lock lock(io_mutex);
std::cout << "i:" << i << "," << ACE_OS::thr_self() << std::endl;
}
}
int counter_;
};
class StaticClass {
public:
static void start() {
boost::thread myThread(&threadFunc);
myThread.join();
}
static void threadFunc(void) {
std::cout << "threadFunc:" << ACE_OS::thr_self() << std::endl;
}
};
class InstanceClass {
public:
void start(void) {
boost::function0<void> f =
boost::bind(&InstanceClass::threadFunc, this);
boost::thread myThread5(f);
myThread5.join();
}
void threadFunc(void) {
std::cout << "threadFunc:Intance," << ACE_OS::thr_self() << std::endl;
}
};
int main(int argc, char * argv[]) {
boost::thread myThread(&myThreadFunc);
myThread.join();
boost::thread myThread2(Counter(5));
myThread2.join();
boost::thread myThread3(Counter(9));
myThread3.join();
StaticClass::start();
InstanceClass instance;
boost::thread mythread6(boost::bind(&InstanceClass::threadFunc, instance));
mythread6.join();
return 0;
}