From a29a321d754c17e784fc883650dbddb8c8142bcc Mon Sep 17 00:00:00 2001 From: "Semere M. Mebrahtom" Date: Sat, 4 Apr 2026 22:56:11 +0200 Subject: [PATCH] changed the circular nature of dongle grabbing to even/odd based to eliminate chained dependency --- Makefile | 4 ++-- coders/coder.c | 2 +- coders/monitor.c | 2 +- coders/utils.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f3dd0a5..50b014b 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ OBJS = $(SRCS:.c=.o) CC = cc # CFLAGS = -Wall -Wextra -Werror -pthread -g -fsanitize=thread -CFLAGS = -Wall -Wextra -Werror +CFLAGS = -Wall -Wextra -Werror -pthread -ARGS = 4 800 200 100 10 3 0 fifo +ARGS = 6 900 200 200 200 10 60 fifo all: $(NAME) diff --git a/coders/coder.c b/coders/coder.c index 3fa72d9..d833011 100644 --- a/coders/coder.c +++ b/coders/coder.c @@ -53,7 +53,7 @@ static void compile_op(t_coder *coder, t_state *state) t_dongle *first; t_dongle *second; - if (coder->right_dongle->idx < coder->left_dongle->idx) + if (coder->idx % 2 == 0) { first = coder->left_dongle; second = coder->right_dongle; diff --git a/coders/monitor.c b/coders/monitor.c index 56dda1d..5ec0b3c 100644 --- a/coders/monitor.c +++ b/coders/monitor.c @@ -14,10 +14,10 @@ static void stop_prog(t_state *state, int i) { + print("%ld %d burned out\n", state, state->coders[i].idx); pthread_mutex_lock(&state->over_mutex); state->is_over = true; pthread_mutex_unlock(&state->over_mutex); - print("%ld %d has burned out\n", state, state->coders[i].idx); } bool is_over(t_state *state) diff --git a/coders/utils.c b/coders/utils.c index 045edfa..74f9127 100644 --- a/coders/utils.c +++ b/coders/utils.c @@ -73,7 +73,7 @@ void print(char *str, t_state *state, int coder_idx) if (!is_over) { pthread_mutex_lock(&state->print_mutex); - printf(str, now() - state->start, coder_idx); + printf(str, now() - state->start, coder_idx + 1); pthread_mutex_unlock(&state->print_mutex); } }