Un ejemplo sencillo que corre en un PIC24 #include <stdio.h> // For printf() #include "pt.h" // Protothreads include static struct pt pt1, pt2; static int protothread1_flag = 0, protothread2_flag = 0; static int protothread1(struct pt *pt){ PT_BEGIN(pt); while(1) { PT_WAIT_UNTIL(pt, protothread1_flag != 0); protothread1_flag = 0; printf("Protothread 1 running\n"); protothread2_flag = 1; } PT_END(pt); } static int protothread2(struct pt *pt){ PT_BEGIN(pt); while(1) { PT_WAIT_UNTIL(pt, protothread2_flag != 0); protothread2_flag = 0; printf("Protothread 2 running\n"); protothread1_flag = 1; } PT_END(pt); } int main(void){ PT_INIT(&pt1); PT_INIT(&pt2); protothread1_flag = 1, protothread2_flag = 0; printf("Protothreads start\n"); while(1) { protothread1(&pt1); protothread2(&pt2); } }
| Salida del programa por la USART: Protothreads start Protothread 1 running Protothread 2 running Protothread 1 running Protothread 2 running Protothread 1 running Protothread 2 running
|