|
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
void task1(int *count)
{
while(*count<5)
{
printf("task1:%d\n",*count);
(*count)++;
sleep(1);
}
}
void task2(int *count)
{
while(*count<5)
{
printf("task2:%d",*count);
(*count)++;
}
}
void cleanup(int a,int b)
{
printf("total:%d\n",a+b);
}
void task1(int *count);
void task2(int*);
void cleanup(int,int);
int g1=0;
int g2=0;
int main()
{
pthread_t th1,th2;
int ret;
ret=pthread_create(&th1,NULL,(void *)task1,(void *)&g1);
if(ret)
{
perror("task1");
exit(EXIT_FAILURE);
}
ret=pthread_create(&th2,NULL,(void *)task2,(void *)&g2);
if(ret)
{
perror("task2");
exit(EXIT_FAILURE);
}
pthread_join(th1,NULL);
pthread_join(th2,NULL);
cleanup(g1,g2);
exit(EXIT_SUCCESS);
}
编译可通过,但是生成的文件无法运行,为什么??
程序有问题吗?
用” gcc -c 文件名 -o 目标 “ 后生成的文件不是可执行文件,并且没有错误提示。不知道是什么原因? |
|