#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
void *calculate(void * arg){
int value = *(int *)arg;
long value_2 = 2*(long)value;
printf("The thread_id is %lu, created by %d\n", pthread_self(), getpid());
sleep(1);
return (void *)value_2;
}
int main()
{
pthread_t pthread_buf;
int n;
//input a number n;
printf("Please input a number n:");
scanf("%d", &n);
//创建一个线程
pthread_create(&pthread_buf, NULL, calculate, &n);
void *result;
pthread_join(pthread_buf, &result);
printf("the result of 2*n is : %ld\n", (long)result);
}
标签:int,create,value,线程,result,pthread,include,void
From: https://blog.51cto.com/u_16470971/8969586