From 2c3773fe0eea57997c3828ea29f8567bd84eff71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20De=20Waele?= <theo.dewaele@student.uclouvain.be> Date: Tue, 12 May 2020 11:42:02 +0200 Subject: [PATCH] Suppression mutex_busy --- prime_divs/data/include/data.h | 2 +- prime_divs/data/src/data.c | 6 +++--- prime_divs/multithreading/src/multithreading.c | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/prime_divs/data/include/data.h b/prime_divs/data/include/data.h index 26024b8..7e22719 100644 --- a/prime_divs/data/include/data.h +++ b/prime_divs/data/include/data.h @@ -36,7 +36,7 @@ typedef struct s_Data int small_factors_size; /**< The size of the allocated buffer Data#small_factors */ int small_factors_count; /**< The number of factors smaller than 2**16 found */ - pthread_mutex_t busy; /**< The mutex used if there is multiple producer threads */ + struct s_Data *next; /**< Link to the next @c Data struct or NULL if it's the end of the list*/ diff --git a/prime_divs/data/src/data.c b/prime_divs/data/src/data.c index 10d65fe..f611b13 100644 --- a/prime_divs/data/src/data.c +++ b/prime_divs/data/src/data.c @@ -74,8 +74,8 @@ Data *Data__init(void) mpz_init(self->N); mpz_init(self->remainder); - // Initialize the busy mutex - pthread_mutex_init(&(self->busy), NULL); + + self->next = NULL; return self; @@ -123,7 +123,7 @@ Data *__Data__destroy(Data *self, void *a __attribute__((unused))) //correction for(int i=0; i < self->big_factors_size; i++) mpz_clear(self->big_factors[i]); - pthread_mutex_destroy(&self->busy); + free(self->big_factors); free(self); diff --git a/prime_divs/multithreading/src/multithreading.c b/prime_divs/multithreading/src/multithreading.c index c27ba3d..8bff1a8 100644 --- a/prime_divs/multithreading/src/multithreading.c +++ b/prime_divs/multithreading/src/multithreading.c @@ -46,15 +46,14 @@ void *produce(void *args) Data *head = (Data*) args; while(head) { - if(pthread_mutex_trylock(&(head->busy)) != EBUSY) - { + //Wait for empty slot lock and insert a node sem_wait(&(threads_buffer->empty)); pthread_mutex_lock(&(threads_buffer->buffer_mutex)); ThreadBuffer__insert(head); pthread_mutex_unlock(&(threads_buffer->buffer_mutex)); sem_post(&(threads_buffer->full)); - } + head = head->next; } -- GitLab