Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
Projet_Q4_Groupe_O4
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneur
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
lepl1503-2020-groupe-O4
Projet_Q4_Groupe_O4
Validations
1561674f
Valider
1561674f
rédigé
5 years ago
par
Arnaud Lefebvre
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Replace main.c
parent
c844a99a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#9902
réussi
5 years ago
Étape : external
Modifications
1
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
Code_With_Threads/main.c
+38
-8
38 ajouts, 8 suppressions
Code_With_Threads/main.c
avec
38 ajouts
et
8 suppressions
Code_With_Threads/main.c
+
38
−
8
Voir le fichier @
1561674f
...
...
@@ -13,11 +13,12 @@ FILE *file_in;
FILE
*
file_out
;
char
*
f_in
;
char
*
f_out
;
int
number_lines
;
//
int number_lines;
int
nthreads
=
1
;
buffer1
*
buffer_1
;
buffer2
*
buffer_2
;
void
*
reading
()
{
file_in
=
fopen
(
f_in
,
"r"
);
if
(
file_in
==
NULL
)
{
...
...
@@ -43,7 +44,10 @@ void *reading() {
pthread_mutex_unlock
(
&
(
buffer_1
->
mutex
));
sem_post
(
&
(
buffer_1
->
full
));
}
pthread_mutex_lock
(
&
(
buffer_1
->
mutex
));
buffer_1
->
can_stop
=
true
;
pthread_mutex_unlock
(
&
(
buffer_1
->
mutex
));
return
EXIT_SUCCESS
;
}
...
...
@@ -52,6 +56,7 @@ void *reading() {
void
*
calculating
()
{
while
(
buffer_1
->
can_stop
==
false
||
buffer_1
->
numbers
->
length
!=
0
)
{
int
number
=
0
;
sem_wait
(
&
(
buffer_1
->
full
));
pthread_mutex_lock
(
&
(
buffer_1
->
mutex
));
number
=
get_node_t
(
buffer_1
->
numbers
);
...
...
@@ -66,15 +71,24 @@ void *calculating() {
pthread_mutex_unlock
(
&
(
buffer_2
->
mutex
));
sem_post
(
&
(
buffer_2
->
full
));
}
//clear_list_t(list_prime);
pthread_mutex_unlock
(
&
(
buffer_2
->
mutex
));
buffer_2
->
can_stop
=
true
;
pthread_mutex_unlock
(
&
(
buffer_2
->
mutex
));
return
EXIT_SUCCESS
;
}
void
*
writing
()
{
/*
number_lines = count_lines(f_in);
while
(
number_lines
!=
0
)
{
number_lines
--
;
while (number_lines > 0) {
number_lines -= 1;
*/
while
(
buffer_2
->
can_stop
==
false
||
buffer_2
->
prime_numbers
->
length
>
0
)
{
sem_wait
(
&
(
buffer_2
->
full
));
pthread_mutex_lock
(
&
(
buffer_2
->
mutex
));
...
...
@@ -82,15 +96,17 @@ void *writing() {
pthread_mutex_unlock
(
&
(
buffer_2
->
mutex
));
sem_post
(
&
(
buffer_2
->
free
));
//printf("removed->first = %d\n", get_at_index(removed, 0));
int
length
=
removed
->
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
fprintf
(
file_out
,
"%d "
,
get_
at_index
(
removed
,
i
));
fprintf
(
file_out
,
"%d "
,
get_
node_t
(
removed
));
}
clear_list_t
(
removed
);
free
(
removed
);
fprintf
(
file_out
,
"
\n
"
);
}
//printf("number_lines = %d \n", number_lines);
return
EXIT_SUCCESS
;
}
...
...
@@ -149,18 +165,32 @@ int main(int argc, char *argv[]) {
if
(
pthread_join
(
read
,
NULL
)
!=
0
)
{
printf
(
"Error with join reading thread.
\n
"
);
return
-
1
;
}
else
{
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
);
}
else
{
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
"
);
return
-
1
;
}
else
{
printf
(
"Calc_thread_join[%d] OK.
\n
"
,
i
);
}
}
if
(
pthread_join
(
write
,
NULL
)
!=
0
)
{
printf
(
"Error with join writing thread.
\n
"
);
return
-
1
;
}
else
{
printf
(
"Write_thread_join OK.
\n
"
);
}
...
...
@@ -177,4 +207,4 @@ int main(int argc, char *argv[]) {
free
(
buffer_2
);
return
0
;
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter