]>
wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-wait.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 função task_wait() (leve)
14 #define WORKLOAD 20000
16 static struct task_t
*pang
, *peng
, *ping
, *pong
, *pung
;
18 // simula um processamento pesado
23 for (int i
= 0; i
< n
; i
++)
24 for (int j
= 0; j
< n
; j
++)
37 printf("%5d ms: %s inicia\n", systime(), (char *)arg
);
38 for (int i
= 0; i
< max
; i
++)
40 printf("%5d ms: %s %d\n", systime(), (char *)arg
, i
);
43 printf("%5d ms: %s termina\n", systime(), (char *)arg
);
48 // corpo da tarefa principal
49 void user_main(void *arg
)
51 int exit_code
, status
;
53 printf("user: inicio\n");
55 pang
= task_create("pang", body
, "\tPang");
57 peng
= task_create("peng", body
, "\t\tPeng");
59 ping
= task_create("ping", body
, "\t\t\tPing");
61 pong
= task_create("pong", body
, "\t\t\t\tPong");
63 pung
= task_create("pung", body
, "\t\t\t\t\tPung");
66 for (int i
= 0; i
< 2; i
++)
68 printf("%5d ms: user %d\n", systime(), i
);
72 printf("%5d ms: user esperando Pang...\n", systime());
73 exit_code
= task_wait(pang
);
74 assert(exit_code
== task_id(pang
));
76 printf("%5d ms: user esperando Peng...\n", systime());
77 exit_code
= task_wait(peng
);
78 assert(exit_code
== task_id(peng
));
80 printf("%5d ms: user esperando Ping...\n", systime());
81 exit_code
= task_wait(ping
);
82 assert(exit_code
== task_id(ping
));
84 printf("%5d ms: user esperando Pong...\n", systime());
85 exit_code
= task_wait(pong
);
86 assert(exit_code
== task_id(pong
));
88 printf("%5d ms: user esperando Pung...\n", systime());
89 exit_code
= task_wait(pung
);
90 assert(exit_code
== task_id(pung
));
92 status
= task_destroy(pang
);
93 assert(status
== NOERROR
);
94 status
= task_destroy(peng
);
95 assert(status
== NOERROR
);
96 status
= task_destroy(ping
);
97 assert(status
== NOERROR
);
98 status
= task_destroy(pong
);
99 assert(status
== NOERROR
);
100 status
= task_destroy(pung
);
101 assert(status
== NOERROR
);
103 printf("%5d ms: user termina\n", systime());