helloworld.pthread.c 450 B

12345678910111213141516171819202122
  1. /* a simple helloworld test, with pthread usage */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <pthread.h>
  5. #include <unistd.h>
  6. void * print (void *arg)
  7. {
  8. printf("child: pid %d\n", getpid());
  9. puts((char *) arg);
  10. return NULL;
  11. }
  12. int main(int argc, char ** argv)
  13. {
  14. pthread_t thread;
  15. printf("parent: pid %d\n", getpid());
  16. pthread_create(&thread, NULL, print, "Hello World!");
  17. pthread_join(thread, NULL);
  18. return 0;
  19. }