diff --git a/Makefile b/Makefile deleted file mode 100644 index 33ce5fd721a6f519ac7b02354b5c967eea89ceb6..0000000000000000000000000000000000000000 --- a/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# This makefile compiles all C files in the same directory and produces a single -# executable named solution -CC = gcc -CFLAGS = -std=gnu17 -Wall -Wextra -pedantic -O2 -g -pthread # this uses the C11 standard, if you want to use a different standard, change it to -std=c[NUMBER] -CPPFLAGS = -MMD -LD_FLAGS = -lm - -BIN_NAME = solution -SRC_FILES = $(wildcard *.c) -OBJ_FILES = $(SRC_FILES:.c=.o) -DEP_FILES = $(wildcard *.d) - -run: $(BIN_NAME) - ./$(BIN_NAME) - -include $(DEP_FILES) - -$(BIN_NAME): $(OBJ_FILES) - $(CC) $(CPPFLAGS) $(LD_FLAGS) $(OBJ_FILES) -o $@ - -%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ - -clean: - @rm -v *.o *.d - @rm -v ./$(BIN_NAME) - -.PHONY: run clean diff --git a/NPVP_Uebung03-1_VincentMeiser_DamianKyfonidis.pdf b/NPVP_Uebung03-1_VincentMeiser_DamianKyfonidis.pdf deleted file mode 100644 index e9de5ac533f0e4d66cc7e9ff5759dce7d39e01e8..0000000000000000000000000000000000000000 Binary files a/NPVP_Uebung03-1_VincentMeiser_DamianKyfonidis.pdf and /dev/null differ diff --git a/README.md b/README.md deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/main.c b/main.c deleted file mode 100644 index fcf376977b316a2708806c0763f2d2ff77a19da1..0000000000000000000000000000000000000000 --- a/main.c +++ /dev/null @@ -1,67 +0,0 @@ -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> - -#define NUM_THREADS 6 - -int UnfallAnzahl; -int checkID; - -pthread_mutex_t lock; - -int check(char c, long tid){ - if (c=='s') { //'s' für Start. Das Auto fährt auf die Brücke - checkID = tid; //und die TID dieses Autos wird gespeichert - printf("Thread %ld enters bridge\n", tid); - } else { //hier 'e' für Ende. Das Auto hat die Brücke überquert. - if (checkID == tid) //Wenn die TID mit der gespeicherten checkID übereinstimmt heißt es kein anderer Thread hat bisher die Brücke betreten da sonst die checkID nicht mit TID übereinstimmen würde. - printf("Thread %ld leaves Bridge \n ----SUCCEEDED!----\n",tid); - else { - printf("UNFALL!\n"); //wenn die TID nicht übereingestimmt hat ist ein Unfall passiert - UnfallAnzahl++; - } - } -} - -void *crossBridge(void *threadid){ - long tid; - int i, _error = 0; - tid = (long) threadid; - for (i=0;i <= 10000; i++) { - _error = pthread_mutex_lock(&lock); - - check('s',tid); //check Funktion um zu gucken ob es einen Unfall gab / geben wird. - usleep(10); //die Dauer wie lange das Auto über die Brücke braucht - - check('e',tid); //check Funktion um zu gucken ob es einen Unfall gab / geben wird. - _error = pthread_mutex_unlock(&lock); - usleep(10); // ohne dieses Warten wurde ein Thread immer hunderte Mal hintereinander ausgeführt. Es konnte also zu weniger Unfällen kommen, da der Thread weniger oft gewechselt wurde, was ich für dieses Programm als unvorteilhaft empfunden hab. - // nach Recherche liegt es wahrscheinlich daran wie der OS scheduler die Threads managed und das kann ich ja nicht beeinflussen. Dementsprechend war das die simpelste Lösung. einfach den aktuellen Prozess für kurze Zeit nicht weiterlaufen aka das Lock nicht sichern lassen. - } - pthread_exit(NULL); -} - -int main(int argc, char *argv[]){ - pthread_t threads[NUM_THREADS]; - int rc; - int t; - int i,j; - - pthread_mutex_init(&lock, NULL); - - for (t = 0; t < NUM_THREADS; t++){ - printf("In main: creating thread %d\n",t); - rc = pthread_create(&threads[t], NULL,crossBridge, (void *)t); - if (rc) { - printf("ERROR, return code ffrom phtread_create() is %d\n",rc); - exit(-1); - } - } - for (t=0; t < NUM_THREADS; t++) { - pthread_join(threads[t], NULL); - } - printf("Anzahl der Unfalle: %d\n", UnfallAnzahl); - - pthread_exit(NULL); -} diff --git a/main.d b/main.d deleted file mode 100644 index b8c24d2c03f415541eac265a66264e951eaaab95..0000000000000000000000000000000000000000 --- a/main.d +++ /dev/null @@ -1 +0,0 @@ -main.o: main.c diff --git a/main.o b/main.o deleted file mode 100644 index 12518cd82f123f46ddaf811caab6275617e2c829..0000000000000000000000000000000000000000 Binary files a/main.o and /dev/null differ diff --git a/solution b/solution deleted file mode 100755 index 2b52a99d2567c77074024cbe391ab85c8812ee5c..0000000000000000000000000000000000000000 Binary files a/solution and /dev/null differ