Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -o thread_function thread_function.c
- #include <stdio.h>
- #include <pthread.h>
- void* thread_function(void *parameters) {
- int number=(int)*((int*)parameters);
- printf("number=%d\n",number);
- char *a = malloc(10);
- if(number==1) strcpy(a,"<Hello World>");
- else strcpy(a,"<Good Night>");
- pthread_exit((void*)a);
- printf("After pthread_exit()\n");
- }
- void* startThreadFunction(void*(*start_routine)(void*),void *parameters) {
- pthread_t thread_id;
- pthread_create (&thread_id,NULL,start_routine,parameters);
- void *returnValue;
- pthread_join(thread_id,&returnValue);
- return returnValue;
- }
- int main(void) {
- int number;
- void *pointer;
- number=2;
- pointer=startThreadFunction(thread_function,&number);
- printf("FINAL STRING: %s POINTER: %p\n",(char*)pointer,pointer);
- number=1;
- pointer=startThreadFunction(thread_function,&number);
- printf("FINAL STRING: %s POINTER: %p\n",(char*)pointer,pointer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement