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();

}

上一篇:.net core 中实现一个堆结构


下一篇:.net core 部署在centos7,验证码不显示