After typing in the following cicode, run
the project and view the effects in the kernel. To view the effects
of not using the semaphore comment out all reference to semaphore
functions below and see its effect in the kernel.
/* Example Using Semaphore Functions
*/
INT hSem;
Function
StartupFunction() !Function to be called at startup
hSem = SemOpen("MySem", 1);
TaskNew("TaskOne","",0);
TaskNew("TaskTwo","",0);
TaskNew("TaskThree","",0);
END
Function
Timer(String sTask)
INT iTime = 0;
TraceMsg("Task " + sTask + " running");
For iTime = 0 TO 5 DO
Sleep(1);
TraceMsg(IntToStr(iTime));
END
TraceMsg("Task " + sTask + " stopped");
SemSignal(hSem);
END
Function
TaskOne()
While 1 Do
SemWait(hSem,-1);
Timer("one");
END
END
Function
TaskTwo()
While 1 Do
SemWait(hSem,-1);
Timer("Two");
END
END
Function
TaskThree()
While 1 Do
SemWait(hSem,-1);
Timer("Three");
END
END
|