1

From assembler point of view, when we make a code that just jumps a few commands back, does not jump to any control function that sheduler might use, how can unix interrupt such a code?

I assume it is using timer and interruptions. So the question is then can we implement unix system on a hardware without interruptions, and still solve the infinite loop code, in finite time?

Or in other words, am I right to assume that the only way unix can deal with code like 'while(true){}' is through hardware timer with interrupts?

And if so, what is a minimum requirement for implementing unix-like system on a hardware without hardware timer+interrupts?

1 Answers1

1

What you discuss is the difference between non-preemptive and preemptive scheduling.

non-preemptive (also called cooperative) is a bit simpler (no timer needed), and it does not need locks when threads communicate. Examples Apple Mac OS9 and earlier, I think early MS-Windows, many embedded systems, and micro-threads.

So yes a timer is needed. However for your question about simplest hardware. Unix needs an MMU and this is far more complex than a timer. (Actually there are Unix like systems that have no MMU and in a lot of situations they work the same (differences are: no security, no swap/paging)

Another way to allow task switching for the while true case. Is to use code injection. The compiler or loader will inject code to cooperatively yield. This can be hard to do: For a loader there may not be enough information to know where is is needed. It may break assumptions of atomicity. Given the right language and compiler, it probably could be done well. However I don't know of any examples.