C++ Mongoose web服务器正在获取当前工作线程
我正在用x线程启动mongoose web服务器。C++ Mongoose web服务器正在获取当前工作线程,c++,c,linux,mongoose-web-server,C++,C,Linux,Mongoose Web Server,我正在用x线程启动mongoose web服务器。 是否有一种方法可以在所有x线程都忙时记录日志,以便在需要时增加线程数?如果不更改Mongoose的代码,这是不可能的。例如,我会在mongoose.c中更改静态void worker\u线程(struct mg\u context*ctx)函数: 当工作线程位于while循环中时(SuthMySoCub(CTX,CONN->客户端)),可以将工作线程视为忙。 关闭_连接(conn)后工作线程可以自由处理套接字队列中的新事件 您可以使用该点计算繁
是否有一种方法可以在所有x线程都忙时记录日志,以便在需要时增加线程数?如果不更改Mongoose的代码,这是不可能的。例如,我会在
mongoose.c
中更改静态void worker\u线程(struct mg\u context*ctx)
函数:
关闭_连接(conn)后代码>工作线程可以自由处理套接字队列中的新事件
您可以使用该点计算繁忙线程的数量。如果不更改Mongoose的代码,这是不可能的。例如,我会在
mongoose.c
中更改静态void worker\u线程(struct mg\u context*ctx)
函数:
关闭_连接(conn)后代码>工作线程可以自由处理套接字队列中的新事件
您可以使用该点计算繁忙线程的数量。正如diewie所建议的,您可以:
- 将“int num_idle”添加到结构mg_上下文中
- 在U插槽中,执行以下操作:
ctx->num_idle++; // If the queue is empty, wait. We're idle at this point. while (ctx->sq_head == ctx->sq_tail && ctx->stop_flag == 0) { pthread_cond_wait(&ctx->sq_full, &ctx->mutex); } ctx->num_idle--; assert(ctx->num_idle >= 0); if (ctx->num_idle == 0) { ... your code ... }
- 将“int num_idle”添加到结构mg_上下文中
- 在U插槽中,执行以下操作:
ctx->num_idle++; // If the queue is empty, wait. We're idle at this point. while (ctx->sq_head == ctx->sq_tail && ctx->stop_flag == 0) { pthread_cond_wait(&ctx->sq_full, &ctx->mutex); } ctx->num_idle--; assert(ctx->num_idle >= 0); if (ctx->num_idle == 0) { ... your code ... }
- 正如迪维建议的那样,您可以: