/* Following is a piece of program that I want the two tasks call the same function 'CommonTask'. But either running on Keil UV2 or other simulators it always runs incorrectly to an unexpected code address. What's wrong with it? */ #include <reg52.h> #include <rtx51tny.h> void Init(void) _task_ 0 { os_create_task(1); os_create_task(2); os_delete_task(0); } /* Common works that I wish the two tasks do. Delete the 'reentrant' declaration of CommonWork, then the program would run normally else it will go wrong. */ void CommonWork(unsigned char ch) reentrant { P3=ch; } void Task1(void) _task_ 1 { for(;;) { EA=0; // Whether the EA is enabled or not is useless to avoid the crash CommonWork('1'); EA=1; } } void Task2(void) _task_ 2 { for(;;) { EA=0; CommonWork('2'); EA=1; } }