Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
Projet 3 - Q6
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
Giovanna Stefanelli
Projet 3 - Q6
Validations
25aabebd
Valider
25aabebd
rédigé
5 years ago
par
Giovanna Stefanelli
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Update fact.c
parent
4f38085c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#6145
en échec
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é
fact.c
+69
-3
69 ajouts, 3 suppressions
fact.c
avec
69 ajouts
et
3 suppressions
fact.c
+
69
−
3
Voir le fichier @
25aabebd
//
//
// Modified on 2
4
/04/2020.
// Modified on 2
6
/04/2020.
//
//
#include
<errno.h>
#include
<errno.h>
#include
<sys/types.h>
#include
<sys/types.h>
...
@@ -141,7 +141,7 @@ void *read_write() {
...
@@ -141,7 +141,7 @@ void *read_write() {
fprintf
(
f
.
out
,
"
\n
"
);
fprintf
(
f
.
out
,
"
\n
"
);
free
(
dividers
);
free
(
dividers
);
}
else
{
}
else
{
fprintf
(
f
.
out
,
"The number %lu is not > 2, discarded
\n
"
,
number
);
fprintf
(
f
.
out
,
"The number %lu is not > 2, discarded
\n
"
,
number
);
}
}
}
}
pthread_exit
((
void
*
)
0
);
// thread exit: normal termination => 0
pthread_exit
((
void
*
)
0
);
// thread exit: normal termination => 0
...
@@ -166,4 +166,70 @@ int main (int argc, char *argv[]) {
...
@@ -166,4 +166,70 @@ int main (int argc, char *argv[]) {
inputfile
=
argv
[
1
];
inputfile
=
argv
[
1
];
outputfile
=
argv
[
2
];
outputfile
=
argv
[
2
];
printf
(
"Thread number not mentioned
\n
"
);
printf
(
"Thread number not mentioned
\n
"
);
printf
(
"The default threads number is %d
\n
"
,
DEFAULT_NO_THREADS
);
printf
(
"The default threads number is %d
\n
"
,
DEFAULT_NO_THREADS
);
\ No newline at end of file
}
else
if
(
argc
==
5
)
{
thread_arg
=
argv
[
1
];
if
(
strcmp
(
thread_arg
,
"-N"
)
!=
0
)
{
printf
(
"%s
\n
"
,
"Wrong input of the option
\n
Use option
\"
-N
\"\n
"
);
exit
(
EXIT_FAILURE
);
}
NO_THREADS
=
atoi
(
argv
[
2
]);
if
(
NO_THREADS
>
MAX_NO_THREADS
)
{
printf
(
"Threads requested > %d
\n
"
,
MAX_NO_THREADS
);
exit
(
EXIT_FAILURE
);
}
inputfile
=
argv
[
3
];
outputfile
=
argv
[
4
];
}
else
{
printf
(
"%s
\n
"
,
"Many or few arguments
\n
"
);
printf
(
"Correct command syntax:
\n
"
);
printf
(
"./fact [-N number_of_threads] input_file.txt output_file.txt
\n\n
"
);
exit
(
EXIT_FAILURE
);
}
/*
* START CLOCK to measure CPU time
* calculate programme performance
*/
/*
clock_t start, end;
double cpu_time_used;
start = clock();
*/
// Open input and output files
f
.
in
=
fopen
(
inputfile
,
"r"
);
f
.
out
=
fopen
(
outputfile
,
"a+"
);
if
((
f
.
in
==
NULL
)
||
(
f
.
out
==
NULL
))
{
printf
(
"Incorrect input_file or output_file name
\n
"
);
exit
(
EXIT_FAILURE
);
}
pthread_t
thread
[
NO_THREADS
];
// thread IDs
// INITIALIZE MUTEX "mutex_readwrite"
if
(
pthread_mutex_init
(
&
mutex_readwrite
,
NULL
)
!=
0
){
printf
(
"
\n
mutex init failed-mutex_readwrite
\n
"
);
exit
(
EXIT_FAILURE
);
}
int
i
;
for
(
i
=
0
;
i
<
NO_THREADS
;
i
++
)
{
pthread_create
(
&
thread
[
i
],
NULL
,
(
void
*
)
read_write
,
NULL
);
}
for
(
i
=
0
;
i
<
NO_THREADS
;
i
++
)
{
pthread_join
(
thread
[
i
],
NULL
);
}
/* END CLOCK to measure CPU time */
/*
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
fprintf(f.out, "\nThe programme execution needed %.3f seconds\n\n", cpu_time_used);
printf("\nThe programme execution needed %.3f seconds", cpu_time_used);
printf("\n -- Programme end --\n");
*/
// Eliminate mutex "mutex_readwrite"
if
(
pthread_mutex_destroy
(
&
mutex_readwrite
)
!=
0
){
printf
(
"
\n
mutex_destroy-mutex_readwrite %s
\n
"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
fclose
(
f
.
in
);
fclose
(
f
.
out
);
return
(
EXIT_SUCCESS
);
}
\ 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