]>
wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-task2.c
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
8 // Teste da gestão básica de tarefas
16 static struct task_t
*task
[NUMTASKS
];
19 void body_task(void *arg
)
25 printf("\tIniciei tarefa %5d\n", id
);
27 // passa o controle para a proxima tarefa
28 next
= ((long)arg
+ 1) % NUMTASKS
;
29 printf("\tVou mudar para a tarefa %d\n", task_id(task
[next
]));
30 task_switch(task
[next
]);
32 printf("\tEncerrei tarefa %5d\n", id
);
37 // corpo da tarefa principal
38 void user_main(void *arg
)
41 char *name
= task_name(NULL
);
43 printf("%s: inicio\n", name
);
46 for (long i
= 0; i
< NUMTASKS
; i
++)
48 task
[i
] = task_create(NULL
, body_task
, (void *)i
);
50 printf("%s: criei a tarefa %d\n", name
, task_id(task
[i
]));
53 // passa o controle para cada uma delas em sequencia
54 for (long i
= 0; i
< NUMTASKS
; i
++)
56 printf("%s: vou ativar a tarefa %d\n", name
, task_id(task
[i
]));
57 status
= task_switch(task
[i
]);
58 assert(status
== NOERROR
);
61 // destroi os descritores
62 for (long i
= 0; i
< NUMTASKS
; i
++)
64 printf("%s: vou destruir a tarefa %d\n", name
, task_id(task
[i
]));
65 status
= task_destroy(task
[i
]);
66 assert(status
== NOERROR
);
69 printf("%s: fim\n", name
);