程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> pthread_mutex_init()實例

pthread_mutex_init()實例

編輯:關於C

 


+ 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]#
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved