OSDev.org

The Place to Start for Operating System Developers
It is currently Sun May 12, 2024 12:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Software Multitasking - What happens when a task finishes?
PostPosted: Thu Aug 02, 2007 6:20 pm 
Offline

Joined: Thu Aug 02, 2007 6:15 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Software Multitasking - What happens when a task finishe
PostPosted: Thu Aug 02, 2007 7:34 pm 
Offline
Member
Member

Joined: Sun Jun 18, 2006 7:21 pm
Posts: 260
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:
;Loader Code
call APP_ENTRY_POINT
;APP Returned back here... obviously... so perform cleanup...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 7:58 pm 
Offline

Joined: Thu Aug 02, 2007 6:15 pm
Posts: 2
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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 11:44 pm 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group