fix valgrind issue
This commit is contained in:
parent
62ddffc0d2
commit
b38d451e9a
1 changed files with 12 additions and 14 deletions
26
src/sched.c
26
src/sched.c
|
@ -71,7 +71,7 @@ sched_init(int nthreads, int qlen, taskfunc f, void *closure)
|
||||||
} else if(nthreads == 0) {
|
} else if(nthreads == 0) {
|
||||||
nthreads = sched_default_threads();
|
nthreads = sched_default_threads();
|
||||||
}
|
}
|
||||||
sched.nthreads = nthreads;
|
sched.nthreads = 0;
|
||||||
|
|
||||||
sched.nthsleep = 0;
|
sched.nthsleep = 0;
|
||||||
|
|
||||||
|
@ -88,33 +88,36 @@ sched_init(int nthreads, int qlen, taskfunc f, void *closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisation du curseur suivant l'état de la pile de chaque processus
|
// Initialisation du curseur suivant l'état de la pile de chaque processus
|
||||||
if(!(sched.top = malloc(sched.nthreads * sizeof(int)))) {
|
if(!(sched.top = malloc(nthreads * sizeof(int)))) {
|
||||||
perror("Cursor top stack");
|
perror("Cursor top stack");
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
if(!(sched.bottom = malloc(sched.nthreads * sizeof(int)))) {
|
if(!(sched.bottom = malloc(nthreads * sizeof(int)))) {
|
||||||
perror("Cursor bottom stack");
|
perror("Cursor bottom stack");
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
for(int i = 0; i < sched.nthreads; ++i) {
|
for(int i = 0; i < nthreads; ++i) {
|
||||||
sched.top[i] = 0;
|
sched.top[i] = 0;
|
||||||
sched.bottom[i] = 0;
|
sched.bottom[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocation mémoire pour la pile de chaque processus
|
// Allocation mémoire pour la pile de chaque processus
|
||||||
if(!(sched.tasks = malloc(sched.nthreads * sizeof(struct task_info *)))) {
|
if(!(sched.tasks = malloc(nthreads * sizeof(struct task_info *)))) {
|
||||||
perror("Stack list");
|
perror("Stack list");
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
for(int i = 0; i < sched.nthreads; ++i) {
|
for(int i = 0; i < nthreads; ++i) {
|
||||||
if(!(sched.tasks[i] = malloc(qlen * sizeof(struct task_info)))) {
|
if(!(sched.tasks[i] = malloc(qlen * sizeof(struct task_info)))) {
|
||||||
fprintf(stderr, "Stack for thread %d: %s\n", i, strerror(errno));
|
fprintf(stderr, "Stack for thread %d: %s\n", i, strerror(errno));
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialise l'aléatoire
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
// Créer les threads
|
// Créer les threads
|
||||||
if(!(sched.threads = malloc(sched.nthreads * sizeof(pthread_t *)))) {
|
if(!(sched.threads = malloc(nthreads * sizeof(pthread_t)))) {
|
||||||
perror("Threads");
|
perror("Threads");
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
|
@ -125,9 +128,6 @@ sched_init(int nthreads, int qlen, taskfunc f, void *closure)
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise l'aléatoire
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
// Démarre les threads
|
// Démarre les threads
|
||||||
for(int i = 0; i < nthreads; ++i) {
|
for(int i = 0; i < nthreads; ++i) {
|
||||||
if(pthread_create(&sched.threads[i], NULL, sched_worker, &sched) != 0) {
|
if(pthread_create(&sched.threads[i], NULL, sched_worker, &sched) != 0) {
|
||||||
|
@ -146,6 +146,7 @@ sched_init(int nthreads, int qlen, taskfunc f, void *closure)
|
||||||
|
|
||||||
return sched_init_cleanup(-1);
|
return sched_init_cleanup(-1);
|
||||||
}
|
}
|
||||||
|
sched.nthreads++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < nthreads; ++i) {
|
for(int i = 0; i < nthreads; ++i) {
|
||||||
|
@ -241,10 +242,7 @@ sched_worker(void *arg)
|
||||||
|
|
||||||
// Récupère le processus courant (index tableau)
|
// Récupère le processus courant (index tableau)
|
||||||
int curr_th;
|
int curr_th;
|
||||||
if((curr_th = current_thread(s)) < 0) {
|
while((curr_th = current_thread(s)) < 0);
|
||||||
fprintf(stderr, "Thread unknown, exiting...\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct task_info task;
|
struct task_info task;
|
||||||
int found;
|
int found;
|
||||||
|
|
Reference in a new issue