helloworld.pthread.c 626 B

12345678910111213141516171819202122232425
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* a simple helloworld test, with pthread usage */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pthread.h>
  7. #include <unistd.h>
  8. void * print (void *arg)
  9. {
  10. printf("child: pid %d\n", getpid());
  11. puts((char *) arg);
  12. return NULL;
  13. }
  14. int main(int argc, char ** argv)
  15. {
  16. pthread_t thread;
  17. printf("parent: pid %d\n", getpid());
  18. pthread_create(&thread, NULL, print, "Hello World!");
  19. pthread_join(thread, NULL);
  20. return 0;
  21. }