#include #include #include #include #include #include "cyclic_scheduler.h" #define CYCLIC_SCHED_PRIO 10 // argumento para los threads de la "aplicación" typedef struct { int id; } thread_data_t; /* * Cuerpo de los threads de la "aplicación" */ void *cyclic_thread_body(void * arg) { int i; thread_data_t my_data = * (thread_data_t *)arg; // execute forever while (1) { for(i=0; i<5; i++) { report ("Run thread ",my_data.id); eat(0.1); } } return NULL; } /* * main: crea el planificador y los threads */ int main() { cyclic_schr_data_t cyclic_schr_data; posix_appsched_scheduler_id_t cyclic_schr_id; pthread_t t1; pthread_attr_t attr; thread_data_t data1 = {1}; cyclic_sched_params_t cyclic_sched_params1 = {.slice = {1, 0}, .id = 1}; // Crea el scheduler posix_appsched_scheduler_ops_t sched_ops = ... CHK( posix_appsched_scheduler_create (...) ); // Crea threads de usuario asigna parámetros ... CHK( pthread_create (&t1, &attr, cyclic_thread_body, &data1) ); // espera para siempre CHK( pthread_join(t1, NULL) ); return 0; }