Software Multitasking - What happens when a task finishes?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
karter16
Posts: 2
Joined: Thu Aug 02, 2007 6:15 pm

Software Multitasking - What happens when a task finishes?

Post by karter16 »

Hi All,

I've been refering to osdev for a while now - it's an awesome resource.
I just have a bit of a question regarding software multitasking.

I have software multitasking working (very basic) on my os and can execute tasks in a round-robbin fashion. My question is: what happens when a task finishes (ie returns)??? what should happen? how should the scheduler know that the task has finished?

or is it necessary to put the task in an infinite loop and somehow send a signal to the scheduler that it has finished? - that doesn't sound very user friendly.

Sorry if this is really obvious or has already been discussed elsewhere but I couldn't find anything about it anywhere.

Cheers,

Matt
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Re: Software Multitasking - What happens when a task finishe

Post by SpooK »

karter16 wrote:Hi All,

I've been refering to osdev for a while now - it's an awesome resource.
I just have a bit of a question regarding software multitasking.

I have software multitasking working (very basic) on my os and can execute tasks in a round-robbin fashion. My question is: what happens when a task finishes (ie returns)??? what should happen? how should the scheduler know that the task has finished?

or is it necessary to put the task in an infinite loop and somehow send a signal to the scheduler that it has finished? - that doesn't sound very user friendly.

Sorry if this is really obvious or has already been discussed elsewhere but I couldn't find anything about it anywhere.

Cheers,

Matt
Standard operating procedure suggests that your provide a form of exit() in the API.

To cover those programs that just tend to "return", your program loader should make a CALL to the program's entry-point so that the final program RET returns back to that same loader (assuming no stack corruption) and follow-up with whatever clean-up code you have.

Generic Example...

Code: Select all

;Loader Code
call APP_ENTRY_POINT
;APP Returned back here... obviously... so perform cleanup...
karter16
Posts: 2
Joined: Thu Aug 02, 2007 6:15 pm

Post by karter16 »

Awesome - That's exactly what I was after! thanks very much :) - I had kinda thought about the exit thing but I know not all programs do it. The call return thing you mentioned is exactly what I needed pointed out to me.

Thanks!
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

In addition, if you want to provide some sort of return value from a process, the general way is to get the return value of main(), store it in the process information structure, and then leave the structure in memory until the process that created the process which exited calls a syscall to get the return value and then deletes the process struct. Then, you run into problems where the calling process exits without getting the return value, leading to a process structure that persists with nothing to remove it. Either you maintain a list of child process' to be removed (if they have terminated) when a parent terminates, or have it done in a separate kernel thread that runs whenever the system is otherwise idle.

Regards,
John.
Post Reply