Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "aufgabe2.h"
- #include <pthread.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #define ANZAHL_TEAMS 4
- #define ANZAHL_RUNDEN 10
- /* Diesen Code nicht modifizieren */
- struct Team teams[] = {{.name = "The Runtime Exceptions", .runtime = 1, .staffelstab = 1, .hand = 1},
- {.name = "Ueberholverbot", .runtime = 2, .staffelstab = 2, .hand = 2},
- {.name = "WiSo nur", .runtime = 5, .staffelstab = 3, .hand = 3},
- {.name = "Die laufenden Kopplungen", .runtime = 3, .staffelstab = 4, .hand = 4}};
- /* Sockel zum Halten des Staffelstabs */
- staffelstab_t sockel;
- /* Ab hier euren Code einfuegen */
- void* func(void* arg)
- {
- struct Team *tem = (struct Team*)arg;
- printf("teamname :%s \n",(*tem).name);
- sleep((*tem).runtime);
- sockel = (*tem).hand;
- int i = 0 ;
- while( i< 9)
- {
- if( sockel == 0)
- {
- printf("%s disqualliviziert \n",(*tem).name);
- }
- else{
- (*tem).hand = sockel;
- }
- sleep((*tem).runtime);
- if(i!= 8)
- {
- sockel= (*tem).hand;
- printf("team %s hat runde %i \n",(*tem).name, (i+1));
- }
- else
- {
- printf("team %s ist im ziel und hält den stab von team %i \n",(*tem).name, (*tem).hand);
- }
- i++;
- }
- pthread_exit(NULL);
- }
- int main(void) {
- int status1;
- int status2;
- int status3;
- int status4;
- pthread_t thread1;
- pthread_t thread2;
- pthread_t thread3;
- pthread_t thread4;
- status1 = pthread_create(&thread1,NULL,&func,(void*)&(teams[0]));
- if (status1) {
- }
- status2 = pthread_create(&thread2,NULL,&func,(void*)&(teams[1]));
- if (status2) {
- }
- status3 = pthread_create(&thread3,NULL,&func,(void*)&(teams[2]));
- if (status3) {
- }
- status4 = pthread_create(&thread4,NULL,&func,(void*)&(teams[3]));
- if (status4) {
- }
- pthread_exit(NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement