pthread_mutex_init()实例
+ thread_mutex.c
/*********************************************************************************
* Copyright: (C) 2013 fulinux
* All rights reserved.
*
* Filename: thread_mutex.c
* Description: This file
*
* Version: 1.0.0(12/05/2013~)
* Author: fulinux
* ChangeLog: 1, Release initial version on 12/05/2013 01:45:43 AM
*
********************************************************************************/
#include
#include
#include
void *function(void *arg);
pthread_mutex_t mutex;
int counter = 0;
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
int rc1, rc2;
char *str1 = fulinux;
char *str2 = wansui!;
pthread_t thread1, thread2;
pthread_mutex_init(&mutex, NULL);
if((rc1 = pthread_create(&thread1, NULL, function, str1)));
{
fprintf(stdout, thread 1 create failed: %d , rc1);
}
if((rc2 = pthread_create(&thread2, NULL,function, str2)));
{
fprintf(stdout, thread 2 create failed: %d , rc2);
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
return 0;
} /* ----- End of main() ----- */
~/cfile/thread_mutex.c[+] CWD: /root/cfile Line: 42/79:8
thread_mutex.c 79L, 2020C written
[root@localhost cfile]# gcc thread_mutex.c -o thread -lpthread
[root@localhost cfile]# ./thread
thread 1 create failed: 0
thread 2 create failed: 0
fulinux /*每秒钟显示一个字符*/
wansui! /*每秒钟显示一个字符*/
[root@localhost cfile]#
>更多相关文章
- 09-29如何通过wrap malloc定位C/C++程序的内存泄漏
- 02-25打车软件大战升级,补贴还能维持多久?
- 12-23BMP文件右旋90度[c语言]
- 12-23寻找直方图中面积最大的矩形(C语言版)
- 12-23[ndk,2]ndk开发案例和错误处理
- 12-23[ndk,1]ndk开发,C语言入门讲解
- 12-23C语言连续存储实现队列机制
- 12-23Objective-c 数据类型
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 05-15奇安信:数据安全问题是医疗卫生行业数字化
- 05-15腾讯宣布混元文生图大模型开源
- 05-15网易云音乐与韩国知名娱乐公司Kakao达成战略
- 05-15阿联酋宣告正式开启“5G-A全国商用”计划,
- 05-15二十年未遇的强烈地磁暴来袭
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御