Electronic – How come RTOSs are considered deterministic

embeddedrtos

On a pc (an OS of course) any C program becomes indeterministic in terms of timing. For instance a loop takes between 1.2 and 1.3 seconds depending on "how fast I am moving another window". It is because the OS makes processes (or threads) share processing power.

As far as RTOSs are concerned (on an embedded system), when we write a multithreading application, I think the same thing happens depending on how many threads are executing concurrently.

I do not have instruments to test this accurately on an embedded system. Thus, I wanted to ask. Is my concern reasonable or am I missing something very fundamental?

EDIT: I will give an example. we have task1(takes 10 ms) and task2(takes 20 ms). They started at the same time on separate two threads. My claim (also concern, not sure) is that task1 takes more than 10ms, because they share processing power with task2.

Best Answer

It's not true that tasks in an RTOS are automatically deterministic, but it's possible to put much tighter constraints on when and how often tasks run. An RTOS will usually provide for hard priorities for tasks; at any time the ready task with the highest priority is running. The author of the code also has total control over what set of tasks are running; you can reasonably expect there are no high priority background tasks that might interrupt your code to, say, swap data to disk, unless you wrote them.

On top of this, some RTOSes provide for cooperative multitasking. In contrast to preemptive multitasking, with cooperative multitasking a task will continue executing until it voluntarily gives up control of the CPU.

Related Topic