helloworld_pthread.c 445 B

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