qfedu-linux-advanced-level/day6/thread7_2.c

36 lines
570 B
C

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void *task1(void *data)
{
int n = *((int *)data);
int ret = 1;
while (n)
{
ret *= n--;
}
// pthread_exit(&ret);
return ret;
}
int main(int argc, char const *argv[])
{
if (argc != 2)
{
printf("usage: ./%s 数字\n", argv[0]);
return 1;
}
pthread_t tid;
int num = atoi(argv[1]);
pthread_create(&tid, NULL, task1, (void *)&num);
int res;
pthread_join(tid, &res);
printf("%d\n", res);
return 0;
}