How to implement multitasking?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

How to implement multitasking?

Post 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?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: How to implement multitasking?

Post 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.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: How to implement multitasking?

Post 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.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: How to implement multitasking?

Post 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. :wink:
Post Reply