day16-重构核心库、使用智能指针(3)
最后将使用这个库的方式进行展示。
1、客户端
在while ((o = getopt(argc, argv, optstring)) != -1)所有的操作都是获取参数的操作,threads 、msgs 和wait 分别指线程数、消息长度以及等待时间。
创建一个长度为threads的线程池,绑定任务(这种方式常用于回调函数的绑定,可以将某个函数与特定的参数值绑定,形成一个新的函数对象,方便在后续使用),将任务不断加入线程池中进行处理。
int main(int argc, char *argv[]) {
int threads = 100;
int msgs = 100;
int wait = 0;
int o = -1;
const char *optstring = "t:m:w:";
while ((o = getopt(argc, argv, optstring)) != -1) {
switch (o) {
case 't':
threads = std::stoi(optarg);
break;
case 'm':
msgs = std::stoi(optarg);
break;

最低0.47元/天 解锁文章
1174

被折叠的 条评论
为什么被折叠?



