pthread_mutex_init()实例

浏览:
字体:
发布时间:2013-12-09 23:23:50
来源:

 


+ 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]#
>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();