本文介绍了pthread的条件循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了使用调用pthread_cond_wait的典型模式是:

 的pthread_mutex_lock(安培;锁定);
  而(!测试)
    调用pthread_cond_wait(安培;条件,和放大器;锁);
调用pthread_mutex_unlock(安培;锁定);

为什么不能if语句来代替while循环。

 的pthread_mutex_lock(安培;锁定);
  如果(!测试)
    调用pthread_cond_wait(安培;条件,和放大器;锁);
调用pthread_mutex_unlock(安培;锁定);


解决方案

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html

The while loop is a very standard way of re-evaluating the predicate, as required by POSIX.

这篇关于pthread的条件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:02
查看更多