0

I am pretty naive to the concept of RTOS, so this question might also be naive :)

While reading about task scheduling in RTOS, i came across the concept that the a non preemptive task can be interrupted if it calls schedule() (On linux based RTOS).

I need to know how actually this function can be called from the c program\application\task? An example will help.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
Anuj Priyadarshi
  • 347
  • 4
  • 16
  • Pretty sure the author of the text you're reading didn't mean `schedule()` as a C function, but meant that the scheduler might have the chance to start executing something else, if he gets the chance, i.e. when the current task (which pretty much is synonymous with process on Linux) yields control or an interrupt of some sort occurred. – Marcus Müller Apr 22 '16 at 06:39
  • Understood, but the idea behind RTOS is the user\programmer can have more control over the scheduling, so are you saying there is no way in RTOS that a user make a task non preemptive and then permit switching as and when required? – Anuj Priyadarshi Apr 22 '16 at 06:43
  • That's a completely different question! – Marcus Müller Apr 22 '16 at 06:44
  • But yes, of course a process can allow for another task to take over. – Marcus Müller Apr 22 '16 at 06:44
  • otherwise, that non-preemptive task would be the only thing that could ever be executed on a single-CPU machine, right? – Marcus Müller Apr 22 '16 at 06:45
  • may be i framed my earlier question in a wrong way, but yes i want to know how can a process allow another task to take over, or permit the scheduler the allow the interference. – Anuj Priyadarshi Apr 22 '16 at 06:45
  • yes. That's easy. Basically, every syscall does that; and the proper way to do it definitely depends on what you're logically doing, but it could for example be something like waiting on `read()` to complete. – Marcus Müller Apr 22 '16 at 06:47
  • that is correct but i believe this is similar is any traditional OS as well, so how does the programmer has more control in case of RTOS. – Anuj Priyadarshi Apr 22 '16 at 06:50
  • That depends on the actual RTOS. Linux itself isn't an RTOS at all – there are -preempt patches, but I don't think they change the API itself. – Marcus Müller Apr 22 '16 at 06:55
  • Notice that I'm no expert in Linux-preempt; I do think you should probably read up on some more simplistic RTOS theory before diving into the very complex Linux OS – Marcus Müller Apr 22 '16 at 06:55
  • 1
    (1) The preemptive kernel is an alternative to the standard Linux kernel. The RT patches are completely different. (2) *"how can a process allow another task to take over..."* -- A Linux process/thread can relinquish the remainder of its excecution time slot by calling **yield()**, which is the basis of cooperative processing (instead of competitive processing). – sawdust Apr 22 '16 at 07:35
  • I would venture to suggest that "linux based RTOS" is an oxymoron. It's either Linux or its an RTOS not both - even with PREEMPT. – Clifford Apr 24 '16 at 16:42

0 Answers0