Skip to content
Extraits de code Groupes Projets
Valider e2d3970b rédigé par Arnaud Lefebvre's avatar Arnaud Lefebvre
Parcourir les fichiers

Replace main.c

parent 1071101e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #10045 réussi
......@@ -17,8 +17,7 @@ char *f_out;
int nthreads = 1;
buffer1 *buffer_1;
buffer2 *buffer_2;
int nlines1;
int nlines2;
int nlines;
void *reading() {
......@@ -56,9 +55,7 @@ void *reading() {
void *calculating() {
int nlines1 = count_lines(f_in);
while ((buffer_1->can_stop == false || buffer_1->numbers->length != 0) && nlines1 != 0) {
nlines1 --;
while (buffer_1->can_stop == false || buffer_1->numbers->length != 0) {
uint64_t number;
sem_wait(&(buffer_1->full));
......@@ -76,17 +73,13 @@ void *calculating() {
sem_post(&(buffer_2->full));
}
pthread_mutex_unlock(&(buffer_2->mutex));
buffer_2->can_stop = true;
pthread_mutex_unlock(&(buffer_2->mutex));
return NULL;
}
void *writing() {
int nlines2 = count_lines(f_in);
while((buffer_2->can_stop == false || buffer_2->prime_numbers->length > 0) && nlines2 != 0) {
nlines2 --;
int nlines = count_lines(f_in);
while (nlines > 0) {
nlines --;
sem_wait(&(buffer_2->full));
pthread_mutex_lock(&(buffer_2->mutex));
......@@ -165,7 +158,6 @@ int main(int argc, char *argv[]) {
printf("Read_thread_join OK.\n");
}
for (int i = 0; i < nthreads; i++) {
if (pthread_cancel(calc[i]) != 0) {
printf("Error with cancel calculating thread[%d].\n", i);
......@@ -173,7 +165,7 @@ int main(int argc, char *argv[]) {
printf("Calc_thread_cancel[%d].\n", i);
}
}
for (int i = 0; i < nthreads; i++) {
if (pthread_join(calc[i], NULL) != 0) {
printf("Error with join calculating thread.\n");
......
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