Skip to content
Extraits de code Groupes Projets
Valider 4050625c rédigé par Laurent Paucot's avatar Laurent Paucot
Parcourir les fichiers

architecture threads

parent abb1250a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #2966 en échec
......@@ -10,12 +10,42 @@
#include <string.h>
#include <pthread.h>
//int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) ; // 0 si réussi et autre valeur sinon
/* premier valeur est un pointeur vers l'identifiant du thread
typedef struct node{
long value;
struct node *next;
}node_t;
typedef struct queue{
struct node *tail;
int size;
}queue_t;
struct buffer_rc{
char *tab[8];
int size;
int len;
};
struct buffer_rc buffer_1 = {.size = 8, .len = 0};
struct buffer_cw
{
queue_t *tab[8];
int size;
int len;
};
struct buffer_cw buffer_2 = {.size = 8, .len = 0};
/* //int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) ; // 0 si réussi et autre valeur sinon
premier valeur est un pointeur vers l'identifiant du thread
* deuxieme est l'attribut de thread
* le troisieme est la fonction a exucter
* dernier argument a passer au thread
*/
void thread_exit(void *ret) ;
// supprimer un thread
......@@ -39,7 +69,9 @@ int pthread_mutex_lock(pthread_mutex_t *mut) ;
int pthread_mutex_unlock(pthread_mutex_t *mut) ;
//detruire un mutex
int pthread_mutex_destroy(pthread_mutex_t *mut) ;
int pthread_mutex_destroy(pthread_mutex_t *mut) ; */
int is_prime(long number) { // Vérifie si number est un nombre premier. Return 1 si il est premier, 0 sinon
......@@ -56,16 +88,6 @@ int is_prime(long number) { // Vérifie si number est un nombre premier. Return
return 1 ; //sinon => VRAI
}
typedef struct node{
long value;
struct node *next;
}node_t;
typedef struct queue{
struct node *tail;
int size;
}queue_t;
queue_t* enqueue(queue_t* q, long val){
......@@ -117,30 +139,40 @@ queue_t* prime_divs(long number){
}
void *writing(void *param){
int run (char *input,char *output){
//getting a list of pr_divs in the buffer #2
FILE *file1 = NULL;
FILE *file2 = NULL;
queue_t *pr_divs = get_from_buffer_2(); //has to be implemented
char *chaine = malloc(sizeof(char[20]));
FILE *file2 = NULL; //juste pour que le code compile
char *chaine = NULL; //idem
file1 = fopen(input,"r");
if (file1 == NULL){return -1;}
struct node *current;
current = malloc(sizeof(node_t));
if (current == NULL){return -1;}
*current = *pr_divs->tail;
current = current->next;
file2 = fopen(output,"w+");
if (file2 == NULL){
fclose(file1);
return -1;
}
fprintf(file2,"%s",chaine);
for (int i = 0; i < pr_divs->size; i++)
{
fprintf(file2," %ld",current->value);
current = current->next;
}
fputc('\n',file2);
while (fgets(chaine,sizeof(char[20]),file1) != NULL){
struct queue *pr_divs;
}
void *calculating(void *param){
//getting lines in the buffer #1
char *chaine = get_from_buffer_1(); //has to be implemented
struct queue *pr_divs;
pr_divs = malloc(sizeof(queue_t));
if (pr_divs == NULL){return -1;}
char *c;
pr_divs = prime_divs(strtol(chaine,NULL,0));
char *ptr;
......@@ -148,24 +180,54 @@ int run (char *input,char *output){
ptr = strchr(chaine,'\n');
*ptr = '\0';
struct node *current;
current = malloc(sizeof(node_t));
if (current == NULL){return -1;}
*current = *pr_divs->tail;
current = current->next;
//putting pr_divs in buffer #2
int err = put_in_buffer_2(); //has to be implemented
}
fprintf(file2,"%s",chaine);
for (int i = 0; i < pr_divs->size; i++)
{
fprintf(file2," %ld",current->value);
current = current->next;
}
fputc('\n',file2);
void *reading (void **param){
FILE *file1 = NULL;
FILE *file2 = NULL;
char *chaine = malloc(sizeof(char[20]));
file1 = fopen((const char*) param[0],"r");
if (file1 == NULL){return -1;}
file2 = fopen((const char*) param[1],"w+");
if (file2 == NULL){
fclose(file1);
return -1;
}
while (fgets(chaine,sizeof(char[20]),file1) != NULL){
//put each line in the buffer #1
int err = put_in_buffer_1(); //has to be implemented
}
fclose(file1);
fclose(file2);
}
int run (char *input,char *output){
pthread_t reader;
pthread_t calculators[4];
pthread_t writer;
int err;
char **arg[2];
arg[0] = input;
arg[1] = output;
err = pthread_create(&reader,NULL,&reading,&arg);
return 0;
......
#ifndef RUN
#define RUN
int is_div(long number, long i);
int is_prime(long number);
typedef struct node{
long value;
struct node *next;
}node_t;
typedef struct queue{
struct node *tail;
int size;
}queue_t;
struct buffer_rc{
char *tab[8];
int size;
int len;
};
struct buffer_cw
{
queue_t *tab[8];
int size;
int len;
};
int is_div(long number, long i);
int is_prime(long number);
int enqueue(queue_t* q, long val);
queue_t* prime_divs(long number);
void *reading (void *param);
void *calculating(void *param);
void *writing(void *param);
int run (char *input,char *output);
#endif
\ No newline at end of file
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