[英]Is it correct to call pthread_cond_wait() and pthread_cond_timedwait() on the same condvar by different threads?
[英]Pthread condvar idiom
我很好奇是否有人使用过类似的东西:
pthread_mutex_lock(&ctx->processing_pipeline.feeder_safe_point_mutex);
while(!ctx->processing_pipeline.feeder_safe_point)
pthread_cond_wait(&ctx->processing_pipeline.feeder_safe_point_cv, &ctx->processing_pipeline.feeder_safe_point_mutex);
pthread_mutex_unlock(&ctx->processing_pipeline.feeder_safe_point_mutex);
...等待condvar。
我们的想法是,当事件完成时, feeder_safe_point
int
变量将被设置为1
,然后等待线程将被唤醒。
另外,建议使用condvars来序列化多个线程的执行方式
是的,这正是你应该如何使用pthreads条件变量。 ctx->processing_pipeline.feeder_safe_point
也应仅在ctx->processing_pipeline.feeder_safe_point_mutex
锁定时进行修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.