12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "pt.h"
- #include <stdio.h> /* For printf(). */
- static int protothread1_flag, protothread2_flag;
- static int
- protothread1(struct pt *pt)
- {
-
- PT_BEGIN(pt);
-
- while(1) {
-
- PT_WAIT_UNTIL(pt, protothread2_flag != 0);
- printf("Protothread 1 running\n");
-
- protothread2_flag = 0;
- protothread1_flag = 1;
-
- }
-
- PT_END(pt);
- }
- static int
- protothread2(struct pt *pt)
- {
- PT_BEGIN(pt);
- while(1) {
-
- protothread2_flag = 1;
-
- PT_WAIT_UNTIL(pt, protothread1_flag != 0);
- printf("Protothread 2 running\n");
-
-
- protothread1_flag = 0;
-
- }
- PT_END(pt);
- }
- static struct pt pt1, pt2;
- int
- main(void)
- {
-
- PT_INIT(&pt1);
- PT_INIT(&pt2);
-
-
- while(1) {
- protothread1(&pt1);
- protothread2(&pt2);
- }
- }
|