Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
L
lepl1503-2020-groupe-C1
Gestion
Activité
Membres
Code
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de conteneur
Registre de modèles
Analyse
Analyse des contributeurs
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
Corentin Lengelé
lepl1503-2020-groupe-C1
Validations
13d779ff
Valider
13d779ff
rédigé
5 years ago
par
Andy Laurez
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
verbose in Main
parent
3608df93
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
main.c
+35
-7
35 ajouts, 7 suppressions
main.c
avec
35 ajouts
et
7 suppressions
main.c
+
35
−
7
Voir le fichier @
13d779ff
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
int
main
(
int
argc
,
char
**
argv
){
int
main
(
int
argc
,
char
**
argv
){
Args
.
nThreads
=
8
;
//default number of threads
Args
.
nThreads
=
8
;
//default number of threads
//getOpt
const
char
*
strOpts
=
"hvN:"
;
const
char
*
strOpts
=
"hvN:"
;
const
struct
option
longOpts
[]
=
{
const
struct
option
longOpts
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"help"
,
no_argument
,
NULL
,
'h'
},
...
@@ -31,6 +33,11 @@ int main(int argc, char** argv){
...
@@ -31,6 +33,11 @@ int main(int argc, char** argv){
Args
.
input_file
=
argv
[
argc
-
2
];
Args
.
input_file
=
argv
[
argc
-
2
];
Args
.
output_file
=
argv
[
argc
-
1
];
Args
.
output_file
=
argv
[
argc
-
1
];
if
(
Args
.
verbose
==
1
){
printf
(
"Number of Threads : %d
\n
"
,
Args
.
nThreads
);
}
//count number of Line
FILE
*
LineCounter
=
fopen
(
Args
.
input_file
,
"r"
);
FILE
*
LineCounter
=
fopen
(
Args
.
input_file
,
"r"
);
if
(
LineCounter
==
NULL
){
if
(
LineCounter
==
NULL
){
printf
(
"Open Error in main for fd LineCounter
\n
"
);
printf
(
"Open Error in main for fd LineCounter
\n
"
);
...
@@ -45,7 +52,9 @@ int main(int argc, char** argv){
...
@@ -45,7 +52,9 @@ int main(int argc, char** argv){
fclose
(
LineCounter
);
fclose
(
LineCounter
);
free
(
line
);
free
(
line
);
printf
(
"counter BEFORE : %d
\n
"
,
counter
);
if
(
Args
.
verbose
==
1
){
printf
(
"counter BEFORE : %d
\n
"
,
counter
);
}
if
(
counter
<
Args
.
nThreads
){
if
(
counter
<
Args
.
nThreads
){
Args
.
nThreads
=
counter
;
Args
.
nThreads
=
counter
;
}
}
...
@@ -78,14 +87,18 @@ int main(int argc, char** argv){
...
@@ -78,14 +87,18 @@ int main(int argc, char** argv){
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
// coumpute fonction
for
(
int
i
=
0
;
i
<
Args
.
nThreads
;
i
++
){
for
(
int
i
=
0
;
i
<
Args
.
nThreads
;
i
++
){
if
(
pthread_create
(
&
threads
[
i
],
NULL
,
&
compute
,
NULL
)
!=
0
){
//TODO: compute function
if
(
pthread_create
(
&
threads
[
i
],
NULL
,
&
compute
,
NULL
)
!=
0
){
printf
(
"Error while creating one of the computing threads
\n
"
);
printf
(
"Error while creating one of the computing threads
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
}
}
//consume fonction
if
(
pthread_create
(
&
writer
,
NULL
,
&
consume
,
NULL
)
!=
0
){
if
(
pthread_create
(
&
writer
,
NULL
,
&
consume
,
NULL
)
!=
0
){
printf
(
"Error while creating the writer thread
\n
"
);
printf
(
"Error while creating the writer thread
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
@@ -110,16 +123,22 @@ int main(int argc, char** argv){
...
@@ -110,16 +123,22 @@ int main(int argc, char** argv){
*/
*/
printf
(
"------------ joined reader ---------------
\n
"
);
if
(
Args
.
verbose
==
1
){
printf
(
"------------ joined reader ---------------
\n
"
);
}
for
(
int
i
=
0
;
i
<
Args
.
nThreads
;
i
++
){
for
(
int
i
=
0
;
i
<
Args
.
nThreads
;
i
++
){
if
(
pthread_join
(
threads
[
i
],
(
void
**
)
&
error
)
!=
0
){
if
(
pthread_join
(
threads
[
i
],
(
void
**
)
&
error
)
!=
0
){
printf
(
"Error while joining one of the computing threads
\n
"
);
printf
(
"Error while joining one of the computing threads
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
printf
(
"---------------------------------one thread finished
\n
"
);
if
(
Args
.
verbose
==
1
){
printf
(
"---------------------------------one thread finished
\n
"
);
}
finished
++
;
finished
++
;
}
}
/*
/*
sem_post(&full2);
sem_post(&full2);
sem_post(&full2);
sem_post(&full2);
...
@@ -130,15 +149,20 @@ int main(int argc, char** argv){
...
@@ -130,15 +149,20 @@ int main(int argc, char** argv){
sem_post(&full2);
sem_post(&full2);
*/
*/
done2
=
0
;
done2
=
0
;
printf
(
"------------- joined compute ------------
\n
"
);
if
(
Args
.
verbose
==
1
){
printf
(
"------------- joined compute ------------
\n
"
);
}
if
(
pthread_join
(
writer
,
(
void
**
)
&
error
)
!=
0
){
if
(
pthread_join
(
writer
,
(
void
**
)
&
error
)
!=
0
){
printf
(
"Error while joining the writer thread"
);
printf
(
"Error while joining the writer thread"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
printf
(
"---------------- join consume ---------------------
\n
"
);
if
(
Args
.
verbose
==
1
){
printf
(
"---------------- join consume ---------------------
\n
"
);
}
sem_destroy
(
&
full
);
sem_destroy
(
&
full
);
...
@@ -153,5 +177,9 @@ int main(int argc, char** argv){
...
@@ -153,5 +177,9 @@ int main(int argc, char** argv){
pthread_mutex_destroy
(
&
mutex2
);
pthread_mutex_destroy
(
&
mutex2
);
div_free_queue
(
buffer2
);
div_free_queue
(
buffer2
);
if
(
Args
.
verbose
==
1
){
printf
(
"Success end"
);
}
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
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