pthread2 pthread_mutex_lock
来源:互联网 发布:苹果软件购买记录 编辑:程序博客网 时间:2024/05/18 19:38
#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <errno.h>#define oops(msg) {perror(msg); exit(errno);}int g_counter = 0;pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;void* add_function(){int i;for(i = 0; i < 100; i++){pthread_mutex_lock(&mutex1); //pthread_mutex_lockg_counter += 2;pthread_mutex_unlock(&mutex1);}}int main(){ pthread_t thread1, thread2; if(pthread_create(&thread1, NULL, add_function, NULL)) oops("pthread_create the thread1"); if(pthread_create(&thread2, NULL, add_function, NULL)) oops("pthread_create the thread2"); pthread_join(thread1, NULL); pthread_join(thread2, NULL); printf("g_counter = %d\n", g_counter); return 0;}
- pthread2 pthread_mutex_lock
- pthread2
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock
- pthread_mutex_lock usage
- pthread_mutex_lock用法
- pthread_mutex_lock 函数
- pthread_mutex_lock 用法
- pthread_mutex_lock实现
- __sync_fetch_and_add,pthread_mutex_lock
- pthread_cond_wait pthread_cond_broadcast pthread_mutex_lock
- pthread_mutex_lock的实现!!
- pthread_mutex_lock引起的core
- HDU 4143 A Simple Problem
- HDU 4320 Arcane Numbers 1(12年多校3-数学)
- jsp页面中文乱码(初学者)
- android SurfaceView实现人物动画
- jquery mobile phonegap中页面跳转白屏及抖动的解决办法<script src="http://code.jquery.com/jquery-1.6.4.min.js"></scri
- pthread2 pthread_mutex_lock
- 黑马程序员---java面向对象思想
- 关于数据库排名函数的使用
- MFC使用NotifyIcon托盘应用程序
- css3
- 深入浅出LDD-6-异步通知
- hdu 3233 Download Manager(模拟题)
- uva147 - Dollars-------水题(精度注意)
- 那时,我们正年轻