Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
L
lepl1503-2020-groupe-M2
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
Laurent Paucot
lepl1503-2020-groupe-M2
Validations
7c8f6624
Valider
7c8f6624
rédigé
5 years ago
par
Laurent Paucot
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
no more leaks
parent
6bb3d269
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#7900
réussi
5 years ago
Étape : external
Modifications
2
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
run.c
+11
-84
11 ajouts, 84 suppressions
run.c
run.h
+26
-13
26 ajouts, 13 suppressions
run.h
avec
37 ajouts
et
97 suppressions
run.c
+
11
−
84
Voir le fichier @
7c8f6624
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
#include
<pthread.h>
#include
<semaphore.h>
#include
<math.h>
int
N
;
//travailler avec des linkendList
typedef
struct
node
{
unsigned
long
long
value
;
struct
node
*
next
;
}
node_t
;
typedef
struct
queue
{
struct
node
*
tail
;
int
size
;
int
final
;
}
queue_t
;
struct
buffer_rc
{
char
**
tab
;
int
size
;
int
len
;
int
head
;
int
tail
;
int
stop
;
FILE
*
file1
;
};
struct
buffer_cw
{
queue_t
**
tab
;
int
size
;
int
len
;
int
head
;
int
tail
;
int
stop
;
FILE
*
file2
;
};
struct
buffer_rccw
{
struct
buffer_rc
*
struct1
;
struct
buffer_cw
*
struct2
;
};
/* sémaphore est une structure de donné qui contient :
*un entier qui stocke la valeur, positive ou nulle du sémaphore.
*une queue qui contient les pointeurs vers les threads
*/
pthread_mutex_t
mutex1
;
sem_t
empty1
;
sem_t
full1
;
pthread_mutex_t
mutex2
;
sem_t
empty2
;
sem_t
full2
;
#include
"run.h"
void
put_in_buffer_1
(
char
*
c
,
struct
buffer_rc
*
ptr
){
//ajouter un element dans le buffer 1
...
...
@@ -83,7 +24,6 @@ char *get_from_buffer_1(struct buffer_rc *ptr){ // chercher dans le buffer 1
}
void
put_in_buffer_2
(
struct
queue
*
ptr
,
struct
buffer_cw
*
buf
){
//ajouter un element dans le buffer 2
buf
->
tab
[
buf
->
head
]
=
malloc
(
sizeof
(
queue_t
*
));
buf
->
tab
[
buf
->
head
]
=
ptr
;
buf
->
len
++
;
//augmente l'espace occupé dans le buffer
buf
->
head
=
(
buf
->
head
+
1
)
%
buf
->
size
;
...
...
@@ -126,28 +66,21 @@ void enqueue(queue_t* q, unsigned long long val){
struct
node
*
ptr
;
ptr
=
malloc
(
sizeof
(
node_t
));
if
(
ptr
==
NULL
){
free
(
ptr
);
//
free(ptr);
return
;}
ptr
->
value
=
val
;
ptr
->
next
=
malloc
(
sizeof
(
node_t
));
if
(
ptr
->
next
==
NULL
){
free
(
ptr
);
return
;
}
if
(
q
->
size
==
0
)
{
*
q
->
tail
=
*
ptr
;
*
ptr
->
next
=
*
ptr
;
q
->
tail
=
ptr
;
ptr
->
next
=
ptr
;
}
else
{
*
ptr
->
next
=
*
q
->
tail
->
next
;
*
q
->
tail
->
next
=
*
ptr
;
ptr
->
next
=
q
->
tail
->
next
;
q
->
tail
->
next
=
ptr
;
}
q
->
size
++
;
free
(
ptr
);
}
...
...
@@ -160,7 +93,6 @@ queue_t* prime_divs(unsigned long long number){
return
NULL
;}
ptr
->
size
=
0
;
ptr
->
final
=
0
;
ptr
->
tail
=
malloc
(
sizeof
(
node_t
));
for
(
unsigned
long
long
i
=
2
;
i
<=
number
/
2
;
i
++
){
if
(
is_div
(
number
,
i
)
&&
is_prime
(
i
)
==
1
){
...
...
@@ -190,13 +122,8 @@ void *writing(void *param){
{
if
(
stop
==
N
-
1
){
for
(
int
i
=
0
;
i
<
param1
->
size
;
i
++
)
{
param1
->
tab
[
i
]
=
NULL
;
}
free
(
param1
->
tab
);
free
(
pr_divs
->
tail
);
free
(
pr_divs
);
free
(
param1
->
tab
);
return
NULL
;
}
free
(
pr_divs
);
...
...
@@ -206,17 +133,18 @@ void *writing(void *param){
FILE
*
file2
=
param1
->
file2
;
node_t
*
current
;
current
=
malloc
(
sizeof
(
node_t
));
if
(
current
==
NULL
){
return
NULL
;}
*
current
=
*
pr_divs
->
tail
;
current
=
pr_divs
->
tail
;
current
=
current
->
next
;
fprintf
(
file2
,
"%llu"
,
current
->
value
);
node_t
*
toFree
=
current
;
current
=
current
->
next
;
for
(
int
i
=
1
;
i
<
pr_divs
->
size
;
i
++
)
{
free
(
toFree
);
toFree
=
current
;
fprintf
(
file2
,
" %llu"
,
current
->
value
);
current
=
current
->
next
;
}
...
...
@@ -224,7 +152,6 @@ void *writing(void *param){
free
(
pr_divs
->
tail
);
free
(
pr_divs
);
free
(
current
);
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
run.h
+
26
−
13
Voir le fichier @
7c8f6624
#ifndef RUN
#define RUN
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
#include
<pthread.h>
#include
<semaphore.h>
#include
<math.h>
#include
<pthread.h>
#include
<semaphore.h>
int
N
;
typedef
struct
node
{
int
N
;
//travailler avec des linkendList
typedef
struct
node
{
unsigned
long
long
value
;
struct
node
*
next
;
}
node_t
;
typedef
struct
queue
{
typedef
struct
queue
{
struct
node
*
tail
;
int
size
;
int
final
;
}
queue_t
;
struct
buffer_rc
{
...
...
@@ -21,8 +27,11 @@ struct buffer_rc{
int
len
;
int
head
;
int
tail
;
int
stop
;
FILE
*
file1
;
};
struct
buffer_cw
{
queue_t
**
tab
;
...
...
@@ -30,6 +39,8 @@ struct buffer_cw
int
len
;
int
head
;
int
tail
;
int
stop
;
FILE
*
file2
;
};
struct
buffer_rccw
{
...
...
@@ -37,6 +48,10 @@ struct buffer_rccw{
struct
buffer_cw
*
struct2
;
};
/* sémaphore est une structure de donné qui contient :
*un entier qui stocke la valeur, positive ou nulle du sémaphore.
*une queue qui contient les pointeurs vers les threads
*/
pthread_mutex_t
mutex1
;
sem_t
empty1
;
sem_t
full1
;
...
...
@@ -46,10 +61,10 @@ sem_t empty2;
sem_t
full2
;
void
put_in_buffer_1
(
char
*
c
);
char
*
get_from_buffer_1
(
void
);
void
put_in_buffer_2
(
struct
queue
*
ptr
);
queue_t
*
get_from_buffer_2
(
void
);
void
put_in_buffer_1
(
char
*
c
,
struct
buffer_rc
*
ptr
);
char
*
get_from_buffer_1
(
struct
buffer_rc
*
ptr
);
void
put_in_buffer_2
(
struct
queue
*
ptr
,
struct
buffer_cw
*
buf
);
queue_t
*
get_from_buffer_2
(
struct
buffer_cw
*
buf
);
int
is_div
(
unsigned
long
long
number
,
unsigned
long
long
i
);
int
is_prime
(
unsigned
long
long
number
);
...
...
@@ -71,6 +86,4 @@ struct buffer_rccw *buff_init_12(struct buffer_rc *ptr1,struct buffer_cw *ptr2);
void
thread_create_join
(
struct
buffer_rc
*
ptr1
,
struct
buffer_cw
*
ptr2
,
struct
buffer_rccw
*
ptr3
);
void
mut_sem_destroy
(
void
);
int
run
(
char
*
input
,
char
*
output
,
int
n_threads
);
#endif
\ No newline at end of file
int
run
(
char
*
input
,
char
*
output
,
int
n_threads
);
\ 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