其他分享
首页 > 其他分享> > muduo中threadpool中一些理解

muduo中threadpool中一些理解

作者:互联网

void threadPool_unittest()

{

threadPool pool("MainThreadPool");

 

pool.setMaxQueueSize(1);

pool.start(5);

 

pool.run(print);

pool.run(print);

 

for (int i = 0; i < 1000; ++i)

{

char buf[32];

snprintf(buf, sizeof buf, "task %d", i);

 

pool.run(std::bind(printString, std::string(buf)));

 

}

//这里是添加一个结束的符号,调用下面三条语句才是真正结束

muduo::CountDownLatch latch(1);

pool.run(std::bind(&muduo::CountDownLatch::countDown, &latch));

latch.wait();

pool.stop();

}

标签:std,muduo,run,threadpool,理解,latch,buf,pool
来源: https://blog.csdn.net/youqi1/article/details/117920142