参考来源https://www.gamedev.net/blogs/entry/2249317-a-guide-to-getting-started-with-boostasio/
std::bind和锁的简单实用
Example 2a
#include
#include
void display(void){
std::cout<<"display"<
结果如下:
Example 2b
#include
#include
class test{
public:
void display(int i){
std::cout<
结果如下:
Example 2c
#include
#include
#include
#include
#include
std::mutex global_lock;
void workerThread(std::shared_ptr io_service ){
global_lock.lock();
std::cout<run();
global_lock.lock();
std::cout< io_service(
new asio::io_service);
std::shared_ptr work(
new asio::io_service::work(io_service));
std::cout<<"Press Enter to exit"< ntid;
for(int i=0;i<4;i++)
{
ntid.push_back(std::thread(workerThread,io_service));
}
std::cin.get();
io_service->stop();
for(auto &iter:ntid){
iter.join();
}
return 0;
}
结果如下: