csci4061/notes/11-threads-code/pthreads_minimal_example.c
Michael Zhang 041f660ccd
f
2018-01-29 17:28:37 -06:00

19 lines
433 B
C

// Minimal example of starting a pthread, passing a parameter to the
// thread function, then waiting for it to finish
#include <pthread.h>
#include <stdio.h>
void *doit(void *param){
int p=(int) param;
p = p*2;
return (void *) p;
}
int main(){
pthread_t thread_1;
pthread_create(&thread_1, NULL, doit, (void *) 42);
int xres;
pthread_join(thread_1, (void **) &xres);
printf("result is: %d\n",xres);
return 0;
}