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

网站建设网上学wordpress文章分类权限

网站建设网上学,wordpress文章分类权限,品牌公司标志设计制作,制作一个.net网站需要条件变量是利用线程间共享得全局变量进行同步的一种机制#xff0c;主要包括两个动作#xff1a;一个线程等待“条件变量的条件成立”而挂起#xff1b;另一个线程使“条件成立”给出条件成立信号。为了防止竞争#xff0c;条件变量得使用总是和一个互斥锁结合在一起。 1、…条件变量是利用线程间共享得全局变量进行同步的一种机制主要包括两个动作一个线程等待“条件变量的条件成立”而挂起另一个线程使“条件成立”给出条件成立信号。为了防止竞争条件变量得使用总是和一个互斥锁结合在一起。 1、创建和注销 条件变量和互斥锁一样有两种创建方式静态方式使用PTHREAD_COND_INITIALIZER动态方式使用pthread_coud_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr)函数cond_attr设置为NULL即可。注销需要使用int pthread_cond_destroy(pthread_cond_t *cond); 2、等待和激发 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)timewait方式表示超过时间条件没有满足则返回ETIMEOUT结束等待 这个time是以绝对时间形式出现即0表示格林尼治时间1970年1月1日0时0分0秒。为了防止多个线程同时请求pthread_cond_wait()需要用互斥锁(mutex)来限定phread_cond_wait()的操作。对cond的操作必须是互斥的。下面是配合pthread_cleanup_push()pthread_cleanup_pop()的一个示例程序 #include pthread.h #include unistd.h #include stdio.h #include stdlib.h #include string.hstruct _Node {int number;struct _Node *next; }; typedef struct _Node Node;Node *head;/*信号量和条件变量*/ static pthread_mutex_t mtx PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond PTHREAD_COND_INITIALIZER;/*线程异常时处理函数*/ static void cleanup_handler(void *arg) {printf(cleanup_handler\n);free(arg);(void)pthread_mutex_unlock(mtx); }/* pthread_cleanup_push注册一个回调函数如果你的线程在对应的pthread_cleanup_pop之前异常退出(return是正常退出其他是异常)那么系统就会执行这个回调函数(回调函数要做什么你自己决定)。但是如果在pthread_cleanup_pop之前没有异常退出pthread_cleanup_pop就把对应的回调函数取消了 */ static void* thread_func(void *arg) {Node *p NULL;printf(in thread_func()\n);/*注册线程异常处理函数*/pthread_cleanup_push(cleanup_handler, p);while (1){pthread_mutex_lock(mtx);while (NULL ! head){/*如果条件不满足则挂起*/pthread_cond_wait(cond, mtx);p head;printf(Got %d from front of queue\n,p-number);free(p);pthread_mutex_unlock(mtx);}}/*清空线程异常处理函数*/pthread_cleanup_pop(0);return 0; }int main() {pthread_t tid;int i;Node *p;pthread_create(tid, NULL, thread_func, NULL);for(i 0; i 10; i){printf(int main():%d, i);p (Node*)malloc(sizeof(Node));p-number i;pthread_mutex_lock(mtx);p-next head;head p;/*通知条件OK了*/pthread_cond_signal(cond);pthread_mutex_unlock(mtx);sleep(1);}printf(thread 1 wanna end then cancel thread2.\n);pthread_cancel(tid);pthread_join(tid, NULL);printf(All done\n);return 0; }输出结果如下 int main():0in thread_func() int main():1Got 1 from front of queue int main():2Got 2 from front of queue int main():3Got 3 from front of queue int main():4Got 4 from front of queue int main():5Got 5 from front of queue int main():6Got 6 from front of queue int main():7Got 7 from front of queue int main():8Got 8 from front of queue int main():9Got 9 from front of queue thread 1 wanna end then cancel thread2. cleanup_handler All done转载于:https://www.cnblogs.com/binmaizhai/archive/2013/03/21/2973554.html
http://www.sadfv.cn/news/147219/

相关文章:

  • 什么是网站改版招标投标公共服务平台
  • 永久免费建网站查域名ip地址查询
  • 悠悠我心的个人网站怎么做大学生网页设计作业
  • 中国机械工业建设集团有限公司网站北京seo优化
  • 湘潭网站建设选择磐石网络在线自助网站按照程序
  • oss做网站网站设计的要求
  • 网站开发checklist长沙企业建站程序
  • 大学专业网站分类目录网站大全
  • 阿里云服务器 多个网站网站死链修复
  • 中小企业网站建设中服务器的解决方案是定制家具设计软件app
  • 海外网站服务器租用手表网站制作照片
  • 专门做水生植物销售网站飞速网站排名
  • 济南网站微信卢松松是用的wordpress
  • 东莞建设工程造价管理网站seo诊断分析工具
  • 什么网站做专利检索报告贵阳网站建设外包
  • 网站设计术语精品网游
  • 做网站是属于哪个专业易游网络验证代理平台
  • 邯郸网站改版找谁做手机访问网站页面丢失
  • 网站设计公司哪家好济南中企动力怎么样
  • 有没有做网站的电话天津首页优化外包公司
  • 北京h5网站建设菜单 标签 wordpress
  • 青岛做家纺的公司网站天津网站建设报价
  • 岑溪网站建设wordpress数据库的名称
  • 大连做网站多少钱网站首页权重
  • 减肥网站如何做网站页面设计培训班
  • 做外贸soho要做网站吗百度收录查询代码
  • 杭州网站的建设wordpress自定义字段分类
  • 网站建设综合实训网络规划设计师2022论文题目
  • 银川制作网站朗格手表网站
  • 信息化建设 调查报告 乡镇网站网络规划设计师知识点