Skip to content
Extraits de code Groupes Projets
Valider 19feade3 rédigé par Corentin Lingier's avatar Corentin Lingier
Parcourir les fichiers
parents bf2d1188 2c3773fe
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #9470 réussi
...@@ -36,7 +36,7 @@ typedef struct s_Data ...@@ -36,7 +36,7 @@ typedef struct s_Data
int small_factors_size; /**< The size of the allocated buffer Data#small_factors */ 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 */ 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*/ struct s_Data *next; /**< Link to the next @c Data struct or NULL if it's the end of the list*/
......
...@@ -74,8 +74,8 @@ Data *Data__init(void) ...@@ -74,8 +74,8 @@ Data *Data__init(void)
mpz_init(self->N); mpz_init(self->N);
mpz_init(self->remainder); mpz_init(self->remainder);
// Initialize the busy mutex
pthread_mutex_init(&(self->busy), NULL);
self->next = NULL; self->next = NULL;
return self; return self;
...@@ -123,7 +123,7 @@ Data *__Data__destroy(Data *self, void *a __attribute__((unused))) //correction ...@@ -123,7 +123,7 @@ Data *__Data__destroy(Data *self, void *a __attribute__((unused))) //correction
for(int i=0; i < self->big_factors_size; i++) for(int i=0; i < self->big_factors_size; i++)
mpz_clear(self->big_factors[i]); mpz_clear(self->big_factors[i]);
pthread_mutex_destroy(&self->busy);
free(self->big_factors); free(self->big_factors);
free(self); free(self);
......
...@@ -46,15 +46,14 @@ void *produce(void *args) ...@@ -46,15 +46,14 @@ void *produce(void *args)
Data *head = (Data*) args; Data *head = (Data*) args;
while(head) while(head)
{ {
if(pthread_mutex_trylock(&(head->busy)) != EBUSY)
{
//Wait for empty slot lock and insert a node //Wait for empty slot lock and insert a node
sem_wait(&(threads_buffer->empty)); sem_wait(&(threads_buffer->empty));
pthread_mutex_lock(&(threads_buffer->buffer_mutex)); pthread_mutex_lock(&(threads_buffer->buffer_mutex));
ThreadBuffer__insert(head); ThreadBuffer__insert(head);
pthread_mutex_unlock(&(threads_buffer->buffer_mutex)); pthread_mutex_unlock(&(threads_buffer->buffer_mutex));
sem_post(&(threads_buffer->full)); sem_post(&(threads_buffer->full));
}
head = head->next; head = head->next;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter