Advertisement
Guest User

Untitled

a guest
May 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include "aufgabe2.h"
  2. #include <pthread.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6.  
  7.  
  8. #define ANZAHL_TEAMS 4
  9. #define ANZAHL_RUNDEN 10
  10.  
  11.  
  12. /* Diesen Code nicht modifizieren */
  13. struct Team teams[] = {{.name = "The Runtime Exceptions", .runtime = 1, .staffelstab = 1, .hand = 1},
  14. {.name = "Ueberholverbot", .runtime = 2, .staffelstab = 2, .hand = 2},
  15. {.name = "WiSo nur", .runtime = 5, .staffelstab = 3, .hand = 3},
  16. {.name = "Die laufenden Kopplungen", .runtime = 3, .staffelstab = 4, .hand = 4}};
  17.  
  18. /* Sockel zum Halten des Staffelstabs */
  19. staffelstab_t sockel;
  20.  
  21. /* Ab hier euren Code einfuegen */
  22. void* func(void* arg)
  23. {
  24. struct Team *tem = (struct Team*)arg;
  25. printf("teamname :%s \n",(*tem).name);
  26.  
  27. sleep((*tem).runtime);
  28. sockel = (*tem).hand;
  29.  
  30. int i = 0 ;
  31. while( i< 9)
  32. {
  33. if( sockel == 0)
  34. {
  35. printf("%s disqualliviziert \n",(*tem).name);
  36. }
  37. else{
  38. (*tem).hand = sockel;
  39. }
  40. sleep((*tem).runtime);
  41. if(i!= 8)
  42. {
  43. sockel= (*tem).hand;
  44. printf("team %s hat runde %i \n",(*tem).name, (i+1));
  45. }
  46. else
  47. {
  48. printf("team %s ist im ziel und hält den stab von team %i \n",(*tem).name, (*tem).hand);
  49. }
  50.  
  51. i++;
  52. }
  53. pthread_exit(NULL);
  54. }
  55.  
  56.  
  57. int main(void) {
  58. int status1;
  59. int status2;
  60. int status3;
  61. int status4;
  62. pthread_t thread1;
  63. pthread_t thread2;
  64. pthread_t thread3;
  65. pthread_t thread4;
  66. status1 = pthread_create(&thread1,NULL,&func,(void*)&(teams[0]));
  67. if (status1) {
  68. }
  69. status2 = pthread_create(&thread2,NULL,&func,(void*)&(teams[1]));
  70. if (status2) {
  71. }
  72. status3 = pthread_create(&thread3,NULL,&func,(void*)&(teams[2]));
  73. if (status3) {
  74. }
  75. status4 = pthread_create(&thread4,NULL,&func,(void*)&(teams[3]));
  76. if (status4) {
  77. }
  78. pthread_exit(NULL);
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement