943,793 Members | Top Members by Rank

Ad:
Apr 8th, 2008
0

got a few homework questions

Expand Post »
1) when is busy wait preferable to blockign wait?

and

2) In a multiprogramming system the execution context of a process (the registers, etc.) is
saved when the scheduler switches out one process and switches in a different process.
In a ‘uniprogramming’ system, there is one process in main memory. Are there
situations where the execution context of the process may have to be saved? Explain.

any help is greatly appreciated
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cppsevennine is offline Offline
3 posts
since Apr 2008
Apr 8th, 2008
0

Re: got a few homework questions

1) I presume busy wait you mean the program displays something like the hourglass you see in browsers where the program continues to do something. The only purpose of the hourglass is to let the user know that the program is doing something that may take some time to complete. The block wait is like the message "Press any key to continue", where the program is actually stopped until you press a key to make it continue. When to use which one all depends on the program and what you the programmer want it to do.

2: >>Are there situations where the execution context of the process may have to be saved
MS-DOS 6.X and older is considerded a "uniprogramming system". The answer is yes because it too has hardware and software interrupts which, as its name implies, interrupts the execution of the main program for a little while to do something else, then when done the interrupt handler will return resume the main program where it left off. This is not a scheduled task switch as it is in multi-programming enviroments such as *nix and MS-Windows.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Apr 8th, 2008
0

Re: got a few homework questions

hey thanks for the help...thats kind of what i figured about the interrupts. as far as the busy wait vs. blocking wait that kind of makes sense. i know busy waits are preferable for tasks that don't take that long to execute. thanks again for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cppsevennine is offline Offline
3 posts
since Apr 2008
Apr 9th, 2008
0

Re: got a few homework questions

Ancient Dragon's first answer seems rather completely wrong. 'Busy waiting' is where a computer checks for input over and over again in a loop. I.e. something that looks like this:

while (eventsPending() == 0) {
}
e = nextEvent();

It is never good to busy wait when a blocking solution is available, since your process will eat up the CPU while busywaiting. It makes much more sense to make a blocking call, because then the kernel can allocate CPU time to other processes. It might make sense to make a non-blocking call if you want your program to do other things in the meantime. I'd rather use threads for that purpose.
Reputation Points: 98
Solved Threads: 22
Posting Whiz in Training
sarehu is offline Offline
269 posts
since Oct 2007
Apr 9th, 2008
0

Re: got a few homework questions

>>Ancient Dragon's first answer seems rather completely wrong
Possible, depending on the definition of "busy waiting". Using your definition I might just check the keyboard for input
while( !kbhit() )
{
   // do some processing
}

I agree with you that coding an empty function like the one you posted is a horrible thing to do because it consumes too much CPU time.
Last edited by Ancient Dragon; Apr 9th, 2008 at 10:09 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Apr 15th, 2008
0

Re: got a few homework questions

I agree that busy wait is not good, but I could think of one rare situation that a process wants to busy wait instead of blocking:

When a process greedily wants to capture an event as soon as possible, so that it probably would not like to give its CPU time slicing away!

But this situation must happens in a multi-processor/multi-core environment, that is, there are two or more processes can run concurrently; otherwise, busy wait totally makes no sense.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jaux is offline Offline
15 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: semaphores
Next Thread in Computer Science Forum Timeline: Datasets for Bellman-Ford algorithm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC