当前位置: 首页 > news >正文

pthread_cond_wait(条件变量)

int pthread_cond_wait
(
   pthread_cond_t * restrict cond,
   pthread_mutex_t *restrict mutex
);
这里参数cond是条件变量并且mutex是一个互斥的锁变量,这个锁必须提前被线程锁住.当这个函数被执行,调用的线程被强迫释放唯一的锁,释放了之后,线程被挂起直到信号被唤醒.换醒线程的函数是pthread_cond_signal(pthread_cond_t *cond);唤醒等待该条件的某个线程.pthread_cond_broadcast(pthread_cond_t *cond);唤醒等待该条件的所有线程.

如果现成接受一个信号,并且被恢复,被重新将唯一的互斥锁锁住.这个函数将不返回直到正在调用的线程已经获得那个锁.

Where the parameter cond is the condition variable and mutex is the mutex previously locked by the calling thread.

When this function executes, the calling thread is forced ( internally ) to release the exclusive lock on the mutex. After the mutex is released, the thread is suspended until signaled. If the thread receives a signal and is resumed it will immediately attempt to re-establish the exclusive lock on the mutex. This function will not return until the calling thread the thread has gained that lock.

A couple of warnings:

* You should NEVER have multiple calls to pthread_cond_wait( ) or it's timed version with the same condition variable and different mutexes.

* You should avoid mixing and matching condition variables and mutexes which have different Process-Shared attributes e.g. one process private and the other process shared.

* You should always check the condition after a thread has returned from a wait. The reason for this is that systems can sometimes cause multiple threads to be unblocked even when the pthread_cond_signal function ( unblock one thread ) is used.

Since a call to pthread_cond_wait( ) suspends the calling thread until it receives a signal the potential exists for the caller to be suspended forever. If you want to place an upper limit on the amount of time the thread will suspend you should use pthread_cond_timewait( ) described below.

 

 

转载于:https://www.cnblogs.com/lowhere/archive/2008/08/20/1272106.html

相关文章:

  • 装了vs2008后再装sql server 2005碰到的问题
  • ArcGIS.Server.9.2.DotNet自带例子分析(七、一)
  • 简述GPS导航设备的定位原理
  • ASP.Net2.0 GridView 多列排序,显示排序图标,分页(转)
  • C#正则表达式类Match和Group类的理解
  • 声音音质评价专业述语
  • 使用Document_Handler_Example修改的注意事项
  • iptables 范例
  • 将asp.net站点转化为sharepoint站点
  • Silverlight是什么
  • Sqlite DateTime 类型 读取和写入格式 注意的问题
  • 文档知多少---走出软件作坊:三五个人十来条枪 如何成为开发正规军(二十五)...
  • 我在博客园里的第一篇文章
  • C#模拟网站用户登录
  • 平时关注.net今个儿用java做了个计算器.
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • conda常用的命令
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • DOM的那些事
  • Fabric架构演变之路
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • JS基础篇--通过JS生成由字母与数字组合的随机字符串
  • JS学习笔记——闭包
  • laravel5.5 视图共享数据
  • MaxCompute访问TableStore(OTS) 数据
  • MYSQL如何对数据进行自动化升级--以如果某数据表存在并且某字段不存在时则执行更新操作为例...
  • PHP CLI应用的调试原理
  • Promise面试题,控制异步流程
  • Promise面试题2实现异步串行执行
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 什么软件可以剪辑音乐?
  • 小程序开发中的那些坑
  • 一道闭包题引发的思考
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • Java数据解析之JSON
  • 翻译 | The Principles of OOD 面向对象设计原则
  • 湖北分布式智能数据采集方法有哪些?
  • #QT(TCP网络编程-服务端)
  • (2/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (C#)获取字符编码的类
  • (java)关于Thread的挂起和恢复
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (安卓)跳转应用市场APP详情页的方式
  • (附源码)spring boot北京冬奥会志愿者报名系统 毕业设计 150947
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (十) 初识 Docker file
  • (顺序)容器的好伴侣 --- 容器适配器
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (转)AS3正则:元子符,元序列,标志,数量表达符
  • (轉)JSON.stringify 语法实例讲解
  • .Net 4.0并行库实用性演练
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution
  • .NET 的静态构造函数是否线程安全?答案是肯定的!
  • .net 写了一个支持重试、熔断和超时策略的 HttpClient 实例池