cooperative
Code: Select all
while (true)
/*event - inner loops*/
idle: SystemTask(); // cycles back
end while
Code: Select all
while (true)
/*event - inner loops*/
idle: Waitms(10); // some ms wait
end while
Possible?
Code: Select all
while (true)
/*event - inner loops*/
idle: SystemTask(); // cycles back
end while
Code: Select all
while (true)
/*event - inner loops*/
idle: Waitms(10); // some ms wait
end while
Code: Select all
REM Operating system here
EVERY (50ms)
IF TaskSwitchNeeded() THEN TaskSwitch();
END EVERY
REM User Task here
REPEAT UserTask
DoUserTaskStuff();
END REPEAT
Code: Select all
REM Operating system here
SystemCall ()
IF TaskSwitchNeeded() THEN TaskSwitch();
DoSystemStuff ();
END SystemCall;
REM User Task here
REPEAT UserTask
DoStuff();
SystemCall();
END REPEAT
Taking best of the two, or a compromise?QDOS is a bit of a mix between the two
Code: Select all
while ( true )
receiveheader()
case ( type )
SND: send()
RCV: receive()
default: waitms( 10 )
end case
end while
Of course the formertcat wrote:Taking best of the two, or a compromise?QDOS is a bit of a mix between the two
The high load in that case is very probably not the result of lack of preemption, but rather your receiveheader(), send() and receive() functions busy-waiting for specific conditions on the network(i.e. checking millions of times per s whether something has changed - with the delay you make sure you only check the same thing every 10ms). In such cases you have a tight loop consuming 100% CPU, even if your system is preemptive (as long as there's nothing else to do, Linux will give 100% to you - QDOS will basically do the same in such cases)tcat wrote:Taking best of the two, or a compromise?QDOS is a bit of a mix between the two
On RPI Linux, not knowing much about scheduler runtime, I coded simple NET [nRF24L01] serverWithout some millis waiting, CPU usage would go to some 20-30% and that's preepmtive system. I know there are some tricks with threads, but was linked as single threaded [hope], as RPI is nowadays multi[core]processor system [used to be single].Code: Select all
while ( true ) receiveheader() case ( type ) SND: send() RCV: receive() default: waitms( 10 ) end case end while
Code: Select all
...
while (GetNextEvent(everyEvent, &myEvent))
{
switch (myEvent.what)
{
case mouseDown:
windowPart = FindWindow(myEvent.where, &whichWindow);
DoMouseDown(windowPart, whichWindow, &myEvent);
break;
case keyDown:
case autoKey:
{
register char theChar;
theChar = myEvent.message & charCodeMask;
if ((myEvent.modifiers & cmdKey) != 0)
return(DoCommand(MenuKey(theChar)));
else if (noCTRL)
KeyDown(theChar);
else
{ gEvent = myEvent;
TESetSelect((**TEH).teLength,(**TEH).teLength,TEH); }
}
break;
case activateEvt:
if (ours((WindowPtr)myEvent.message))
{
if (myEvent.modifiers & activeFlag)
{ TEActivate(TEH);
ShowControl(vScroll);
DisableItem(myMenus[editM], undoCommand); }
else
{ TEDeactivate(TEH);
HideControl(vScroll); }
}
break;
case updateEvt:
if (ours((WindowPtr) myEvent.message))
UpdateWindow(myWindow);
break;
}
}
...
Code: Select all
while (1);
Code: Select all
switch () ...
default: Idle()
}
I don't know how Windows 3 did things so maybe Idle() is from that software architecture.If you intend to design your application to run in either a single-application environment (such as System 6 without MultiFinder) or a multiple-application environment, the very beginning of your event loop should test to make sure the WaitNextEvent function is available. If WaitNextEvent is not available, your code should use GetNextEvent to retrieve events. If your code uses GetNextEvent, it should also call SystemTask to allow desk accessories to perform periodic actions. However, your code should always use WaitNextEvent if it is available, rather than GetNextEvent. If your application calls WaitNextEvent, it should not call the SystemTask procedure.
Hi Thomas,tcat wrote:Hi Ben,
Nice event loop example, I vaguely remember programmers were also guided to addwhenever appropriate, to do some app housekeeping, while it is idle, which is most of the time.Code: Select all
switch () ... default: Idle() }
Yes, while(1) or until(0)