Advertisement
jckuri

thread_function.c

Jun 24th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. // thread_function.c
  2. // gcc -o thread_function thread_function.c
  3.  
  4. #include <stdio.h>
  5. #include <pthread.h>
  6. #include <stdlib.h>
  7.  
  8. void* thread_function(void) {
  9.  char *a = malloc(10);
  10.  strcpy(a,"<Hello World>");
  11.  pthread_exit((void*)a);
  12. }
  13.  
  14. int main() {
  15.  pthread_t thread_id;
  16.  char *b;
  17.  pthread_create (&thread_id, NULL,&thread_function, NULL);
  18.  // Here we are reciving one pointer value. Thus, we need double pointer:
  19.  pthread_join(thread_id,(void**)&b);
  20.  printf("b is %s\n",b);  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement