最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺析Linux下一個簡單的多線程互斥鎖的例子

 更新時間:2013年07月09日 11:21:08   作者:  
本篇文章是對Linux下一個簡單的多線程互斥鎖的例子進行了分析介紹,需要的朋友可以參考下
復(fù)制代碼 代碼如下:

#include <stdio.h>
#include <pthread.h>
pthread_mutex_t Device_mutex ;
int count=0;
void thread_func1()
{
   while(1)
   {
       pthread_mutex_lock(&Device_mutex);
       printf("thread1: %d\n",count);
       pthread_mutex_unlock(&Device_mutex);
       count++;
       sleep(1);
   }
}
void thread_func2()
{
   while(1)
   {
       pthread_mutex_lock(&Device_mutex);
       printf("thread2: %d\n",count);
       pthread_mutex_unlock(&Device_mutex);
       count++;
       sleep(1);
   }
}
int main()
{
   pthread_t thread1, thread2;
   pthread_mutex_init(&Device_mutex,NULL);
   if(pthread_create(&thread1,NULL,(void*)thread_func1,NULL) == -1)
 {
  printf("create IP81 Thread error !\n");
  exit(1);
 }
 sleep(1);
 if(pthread_create(&thread2,NULL,(void *)thread_func2,NULL) == -1)
 {
  printf("create IP81_2 Thread error!\n");
  exit(1);
 }
 sleep(1);
 pthread_join(thread1,NULL);
 pthread_join(thread2,NULL);
 pthread_mutex_destroy(&Device_mutex);
 return 0;
}

相關(guān)文章

最新評論

上杭县| 广宁县| 治县。| 盘山县| 嘉兴市| 澄城县| 珲春市| 阿坝县| 平邑县| 榆中县| 遵义市| 乐陵市| 秦皇岛市| 重庆市| 尖扎县| 石楼县| 滨海县| 崇信县| 加查县| 抚州市| 太仆寺旗| 四平市| 和硕县| 普安县| 白山市| 东阿县| 正蓝旗| 仪陇县| 新泰市| 屏东市| 桑植县| 德阳市| 丹阳市| 平原县| 万载县| 墨竹工卡县| 黄平县| 宁强县| 周口市| 文化| 郴州市|