Page 1 of 1
How to implement multitasking?
Posted: Fri Mar 28, 2014 7:50 pm
by Roman
My current project is a simple 16-bit real mode OS without multitasking, though I am interested, how to implement it? (multitasking) Is there any CPU level way to execute two binaries at same time?
Re: How to implement multitasking?
Posted: Fri Mar 28, 2014 8:14 pm
by sortie
Search the forums. This has been discussed in depth before!
I think the short version is that this is cracy, real mode is obsolete, you are wasting your time, use a 32 bit or 64 mode.
Re: How to implement multitasking?
Posted: Fri Mar 28, 2014 11:31 pm
by Bender
Multitasking as I see it, isn't really multitasking, Multitasking I think doesn't exist at all, IMO multitasking is a way to fool the user that two tasks are running simultaneously, but they are not. I think you use a timer interrupt or a keyboard interrupt (depending upon your design) to switch tasks. Each task must be given a specific period of time (preemptive), if you set the PIT (you can also use the RTC Interrupt, but that's not accurate as PIT) to say 10hz then each task will be given a period of 0.1 seconds, the CPU will switch tasks after every 0.1 seconds. Remember to save the registers of the tasks before switching to a new task.
Say you have two tasks A and B, both the tasks print numbers from 0 to infinity, Both start at the same time, now every timer tick (assuming you've used a timer) the CPU will switch between these tasks, and it'll be so quick for our eyes to notice.....
PS. I am in sleep mode writing this so I may have missed something.
Re: How to implement multitasking?
Posted: Fri Mar 28, 2014 11:35 pm
by bluemoon
Bender wrote:Multitasking as I see it, isn't really multitasking, Multitasking I think doesn't exist at all, IMO multitasking is a way to fool the user that two tasks are running simultaneously, but they are not.
Since more than thirty years ago there exist multi-processor machines. Two tasks can be running simultaneously on different cpu.
By the way, the world has defined multi-tasking in a bit different than yours. To get start, check cooperative multi-tasking - it IS called multitasking even they do not run simultaneously.