Advertisement
Guest User

Untitled

a guest
May 3rd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <pthread.h>
  5. #include <stdlib.h>
  6.  
  7. void *erhoehenumeins(void *dummy)
  8. {
  9. printf("Thread erhoehenumeins() wurde gestartet\n");
  10. int *temp = (int *) dummy;
  11. *temp++;
  12. printf("Thread erhoehenumeins() wurde beendet\n");
  13. printf("Ergebnis=%d\n",temp);
  14. }
  15.  
  16. void *verdoppeln(void * dummy)
  17. {
  18. printf("Thread verdoppeln() wurde gestartet\n");
  19. int *temp = (int *) dummy;
  20. *temp *= 2;
  21. printf("Thread verdoppeln() wurde beendet\n");
  22. printf("Ergebnis=%d\n",temp);
  23. }
  24.  
  25. int main() {
  26. int ergebnis=3;
  27. pthread_t thread1, thread2;
  28.  
  29. // Thread 1 erzeugen
  30. pthread_create( &thread1, NULL, &erhoehenumeins, &ergebnis );
  31.  
  32. // Thread 2 erzeugen
  33. pthread_create( &thread2, NULL, &verdoppeln, &ergebnis );
  34.  
  35. // Main-Thread wartet auf beide Threads.
  36. pthread_join( thread1, NULL );
  37. pthread_join( thread2, NULL );
  38.  
  39. printf("\nHaupt-Thread main() wurde beendet\n");
  40. exit(0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement