diff --git a/NPVP_Uebung04-VincentMeiser_DamianKyfonidis.pdf b/NPVP_Uebung04-VincentMeiser_DamianKyfonidis.pdf deleted file mode 100644 index 74dabf9019769794e524f061249031c936e5a58f..0000000000000000000000000000000000000000 Binary files a/NPVP_Uebung04-VincentMeiser_DamianKyfonidis.pdf and /dev/null differ diff --git a/uebung4-1/Makefile b/uebung4-1/Makefile deleted file mode 100644 index af86ed314036bad6398eac21c688b966dfaadc42..0000000000000000000000000000000000000000 --- a/uebung4-1/Makefile +++ /dev/null @@ -1,29 +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 -CPPFLAGS = -MMD -LD_FLAGS = -pthread -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) $(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/uebung4-1/main.c b/uebung4-1/main.c deleted file mode 100644 index 782899d9b2bd75d2cfe8a11a8922a1d4e7d18d49..0000000000000000000000000000000000000000 --- a/uebung4-1/main.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <pthread.h> -#include <unistd.h> - -#define philo_NUM 5 - -pthread_mutex_t locks[philo_NUM]; //jede Gabel kriegt ihr eigenes Lock -pthread_t philosophen[philo_NUM]; - -void* philosopher(void* threadid) { - int id = *(int*)threadid; //hier habe ich mir KI hilfe holen lassen. (long) tid hat irgendwie nicht funktioniert - int i = 0; - - for (i=0;i <= 10000; i++) { - printf("Philosoph %d denkt nach.\n", id); - usleep(100); //Denkzeit - - printf("Philosoph %d hat Hunger.\n", id); - - pthread_mutex_lock(&locks[id]); //linke Gabel nehmen - pthread_mutex_lock(&locks[(id + 1) % philo_NUM]); //rechte Gabel nehmen - - printf("Philosoph %d isst.\n", id); - usleep(100); //Essenszeit - - pthread_mutex_unlock(&locks[(id + 1) % philo_NUM]); //rechte Gabel zurücklegen - pthread_mutex_unlock(&locks[id]); //linke Gabel zurücklegen - - } - pthread_exit(NULL); -} - -int main() { - int ids[philo_NUM]; - - - for (int i = 0; i < philo_NUM; i++) { - pthread_mutex_init(&locks[i], NULL); // Initialisierung von locks anstelle von forks - } - - for (int i = 0; i < philo_NUM; i++) { //Threads erstellen - ids[i] = i; - pthread_create(&philosophen[i], NULL, philosopher, &ids[i]); - } - - for (int i = 0; i < philo_NUM; i++) { - pthread_join(philosophen[i], NULL); - } - - pthread_exit(NULL); -} diff --git a/uebung4-3/Makefile b/uebung4-3/Makefile deleted file mode 100644 index af86ed314036bad6398eac21c688b966dfaadc42..0000000000000000000000000000000000000000 --- a/uebung4-3/Makefile +++ /dev/null @@ -1,29 +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 -CPPFLAGS = -MMD -LD_FLAGS = -pthread -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) $(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/uebung4-3/main.c b/uebung4-3/main.c deleted file mode 100644 index 8246cf46b46217de92aad8a316580318192063aa..0000000000000000000000000000000000000000 --- a/uebung4-3/main.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> - -#define philo_NUM 5 - -pthread_mutex_t locks[philo_NUM]; //jede Gabel kriegt ihr eigenes Lock - -void* philosoph(void* theadid) { - int id = *(int*)theadid; - - for (int i = 0; i <= 10000; i++) { - printf("Philosoph %d denkt nach.\n", id); - usleep(100); // Denkzeit - - printf("Philosoph %d hat Hunger.\n", id); - - if (id % 2 == 0) { //alle gerade Philosophen - // zuerst Linke dann rechte Gabel - pthread_mutex_lock(&locks[id]); - pthread_mutex_lock(&locks[(id + 1) % philo_NUM]); - } else { //alle ungerade Philosophen - // zuerst Rechte dann linke Gabel - pthread_mutex_lock(&locks[(id + 1) % philo_NUM]); - pthread_mutex_lock(&locks[id]); - } - - printf("Philosoph %d isst.\n", id); - usleep(100); // Essenszeit - - // Gabeln zurücklegen - pthread_mutex_unlock(&locks[(id + 1) % philo_NUM]); - pthread_mutex_unlock(&locks[id]); - } - - pthread_exit(NULL); -} - - -int main() { - pthread_t threads[philo_NUM]; - int philosoph_nummern[philo_NUM]; - - for (int i = 0; i < philo_NUM; i++) { //Mutexes initialisieren - pthread_mutex_init(&locks[i], NULL); - } - - for (int i = 0; i < philo_NUM; i++) { //Threads erstellen - philosoph_nummern[i] = i; - pthread_create(&threads[i], NULL, philosoph, &philosoph_nummern[i]); - } - - for (int i = 0; i < philo_NUM; i++) { - pthread_join(threads[i], NULL); - } - - pthread_exit(NULL); -}