#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#define Max 10
pthread_t thread[2];
pthread_mutex_t mut;
int number=0;
int A;
void *thread1()
{
A =5 ;
printf("thread1:I'm thread 1\n");
A=A+1;
printf("%d\n",A);
}
void *thread2()
{
A=5;
A=A+1;
printf("thread2:I'm thread 2\n");
printf("%d\n",A);
}
void thread_create()
{
int temp;
memset(&thread,0,sizeof(thread));
if(temp == pthread_create(&thread[0],NULL,thread1,NULL)!=0)
printf("线程1创建失败!\n");
else
printf("线程1被创建!\n");
if(temp == pthread_create(&thread[1],NULL,thread2,NULL)!=0)
printf("线程2创建失败!\n");
else
printf("线程2被创建!\n");
}
int main()
{
printf("线程1创建失败!\n");
printf("主线程!\n");
int i=0;
//for(i=0;i<20;i++)
//{
thread_create();
//pthread_join(thread[0],NULL);
//pthread_join(thread[1],NULL);
pthread_exit(&thread[0]);
pthread_exit(&thread[1]);
// }
return 0;
}
第一次写unix多线程代码
最新推荐文章于 2023-05-13 18:07:02 发布