removed incorrect burnout log after all coders were done

This commit is contained in:
Semere M. Mebrahtom 2026-03-26 13:58:01 +01:00
parent b171edf043
commit 6772407a3c
Signed by: semere
GPG key ID: 7FC937214DF30488
3 changed files with 18 additions and 11 deletions

View file

@ -8,6 +8,7 @@ OBJS = $(SRCS:.c=.o)
CC = cc CC = cc
# CFLAGS = -Wall -Wextra -Werror -pthread -g # CFLAGS = -Wall -Wextra -Werror -pthread -g
CFLAGS = -Wall -Wextra -Werror -pthread -g -fsanitize=thread CFLAGS = -Wall -Wextra -Werror -pthread -g -fsanitize=thread
ARGS = 2 800 200 100 10 3 0 edf
all: $(NAME) all: $(NAME)
@ -27,13 +28,13 @@ $(NAME): $(OBJS)
# scheduler # scheduler
test: $(NAME) test: $(NAME)
./$(NAME) 2 800 200 100 10 3 0 edf ./$(NAME) $(ARGS)
test-val: $(NAME) test-val: $(NAME)
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) 2 800 200 100 10 5 0 edf valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) $(ARGS)
test-hel: $(NAME) test-hel: $(NAME)
valgrind --tool=helgrind ./$(NAME) 2 800 200 100 10 5 0 edf valgrind --tool=helgrind ./$(NAME) $(ARGS)
clean: clean:
rm -f $(OBJS) rm -f $(OBJS)

View file

@ -49,7 +49,7 @@ typedef struct s_coder
long last_compile; long last_compile;
int compiles_done; int compiles_done;
t_state *state; t_state *state;
pthread_mutex_t last_mutex; pthread_mutex_t info_mutex;
} t_coder; } t_coder;
typedef struct s_state typedef struct s_state

View file

@ -64,14 +64,14 @@ void compile_op(t_coder *coder, t_state *state)
pthread_mutex_lock(&second->lock); pthread_mutex_lock(&second->lock);
second->last_used = now(); second->last_used = now();
print("%ld %d has taken a dongle\n", state, coder->idx); print("%ld %d has taken a dongle\n", state, coder->idx);
pthread_mutex_lock(&coder->last_mutex); pthread_mutex_lock(&coder->info_mutex);
coder->last_compile = now(); coder->last_compile = now();
pthread_mutex_unlock(&coder->last_mutex); coder->compiles_done += 1;
pthread_mutex_unlock(&coder->info_mutex);
print("%ld %d is compiling\n", state, coder->idx); print("%ld %d is compiling\n", state, coder->idx);
usleep(state->args.time_to_compile * 1000L); usleep(state->args.time_to_compile * 1000L);
pthread_mutex_unlock(&first->lock); pthread_mutex_unlock(&first->lock);
pthread_mutex_unlock(&second->lock); pthread_mutex_unlock(&second->lock);
coder->compiles_done += 1;
} }
void debug_op(t_coder *coder, t_state *state) void debug_op(t_coder *coder, t_state *state)
@ -116,17 +116,20 @@ void *monitor(void *param)
t_state *state; t_state *state;
int i; int i;
long last; long last;
int compiles_done;
state = param; state = param;
while (!is_over(state)) compiles_done = 0;
while (compiles_done < state->args.number_of_compiles_required
&& !is_over(state))
{ {
usleep(1000); usleep(1000);
i = -1; i = -1;
while (++i < state->args.number_of_coders) while (++i < state->args.number_of_coders)
{ {
pthread_mutex_lock(&state->coders[i].last_mutex); pthread_mutex_lock(&state->coders[i].info_mutex);
last = state->coders[i].last_compile; last = state->coders[i].last_compile;
pthread_mutex_unlock(&state->coders[i].last_mutex); pthread_mutex_unlock(&state->coders[i].info_mutex);
if (now() - last >= state->args.time_to_burnout) if (now() - last >= state->args.time_to_burnout)
{ {
pthread_mutex_lock(&state->over_mutex); pthread_mutex_lock(&state->over_mutex);
@ -136,6 +139,9 @@ void *monitor(void *param)
return (NULL); return (NULL);
} }
} }
pthread_mutex_lock(&state->coders[i - 1].info_mutex);
compiles_done = state->coders[i - 1].compiles_done;
pthread_mutex_unlock(&state->coders[i - 1].info_mutex);
} }
return (NULL); return (NULL);
} }
@ -199,7 +205,7 @@ t_coder *init_coders(t_args *args, t_state *state)
coders[i].right_dongle = &state->dongles[(i + 1) coders[i].right_dongle = &state->dongles[(i + 1)
% args->number_of_coders]; % args->number_of_coders];
coders[i].state = state; coders[i].state = state;
pthread_mutex_init(&coders[i].last_mutex, NULL); pthread_mutex_init(&coders[i].info_mutex, NULL);
} }
return (coders); return (coders);
} }