Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!gatech!gitpyr!duke From: duke@gitpyr.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: How do you do concurrency? Message-ID: <3384@gitpyr.gatech.EDU> Date: Fri, 3-Apr-87 23:20:33 EST Article-I.D.: gitpyr.3384 Posted: Fri Apr 3 23:20:33 1987 Date-Received: Sun, 5-Apr-87 08:52:26 EST References: <1328@erix.UUCP> Organization: Georgia Institute of Technology Lines: 30 Summary: Concurrency on an IBM PC In article <1328@erix.UUCP>, mike@erix.UUCP (Mike Williams) writes: > Several systems like MS-WINDOWS or GEM allow users to run several > processes concurently in MS-DOS. By this I mean allow several processes > to time share the CPU: > > How is this done? I know the basic principles of time sharing operating > systems, this question really means, how is this done in MS-DOS? Are > there any available software procedures which allow one to do this > oneself? > I can't speak for how Windows does multitasking, but I can describe a method which will work. If you steal an interrupt, such as the timer interrupt, and have the interrupt vector point to some machine code you have written to save the contents of all registers, then you will successfully have saved the context of the currently running process. The interrupt will save the contents of the instruction pointer and flags on top of the current stack. To save the contents of all registers, simply push them on top of the current stack. Then you need only remember the stack segment (SS) and stack pointer (SP). To restore the context of a process, all you need to do is load the SS and SP and then pop all registers off the stack in the reverse order you pushed them, and then issue a return from interrupt. On a timer interrupt, you would simply swap the context of a process to one which is currently waiting to execute. Obviously, this would mean you must initialize the stack of a process upon creation to look as though it has just had its context saved following an interrupt. I'm not sure if I explained the process very well, but I hope you get the general idea. If anything is unclear or you have any questions, I will be more than happy to expand on anyting I have said.