This repository has been archived on 2024-05-05. You can view files and clone it, but cannot push or open issues or pull requests.
work-stealing-scheduler/src/sched.c

29 lines
638 B
C
Raw Normal View History

#include "../includes/sched.h"
2024-03-09 18:47:40 +01:00
2024-03-15 12:43:44 +01:00
#include <pthread.h>
#include <stdio.h>
2024-03-09 18:47:40 +01:00
int sched_init(int nthreads, int qlen, taskfunc f, void *closure) {
2024-03-15 12:43:44 +01:00
sched_spawn(f, closure, NULL);
return 0;
2024-03-09 18:47:40 +01:00
}
int sched_spawn(taskfunc f, void *closure, struct scheduler *s) {
2024-03-15 12:43:44 +01:00
pthread_t thread;
int errno;
// Création d'un thread pour la tâche
if ((errno = pthread_create(&thread, NULL, (void *)f, closure)) != 0) {
fprintf(stderr, "pthread_create error %d\n", errno);
return -1;
}
// Attend la fin du thread
if ((errno = pthread_join(thread, NULL)) != 0) {
fprintf(stderr, "error %d\n", errno);
return -1;
}
return 0;
2024-03-09 18:47:40 +01:00
}