User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 403,413 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,744 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 589 | Replies: 5 | Solved
Reply
Join Date: Apr 2008
Posts: 3
Reputation: cppsevennine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cppsevennine cppsevennine is offline Offline
Newbie Poster

got a few homework questions

  #1  
Apr 8th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,743
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 884
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: got a few homework questions

  #2  
Apr 8th, 2008
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.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Apr 2008
Posts: 3
Reputation: cppsevennine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cppsevennine cppsevennine is offline Offline
Newbie Poster

Re: got a few homework questions

  #3  
Apr 8th, 2008
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
Reply With Quote  
Join Date: Oct 2007
Location: Cambridge, MA
Posts: 247
Reputation: sarehu is on a distinguished road 
Rep Power: 1
Solved Threads: 21
sarehu's Avatar
sarehu sarehu is offline Offline
Posting Whiz in Training

Re: got a few homework questions

  #4  
Apr 9th, 2008
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.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,743
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 884
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: got a few homework questions

  #5  
Apr 9th, 2008
>>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 9:09 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Oct 2007
Posts: 12
Reputation: jaux is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

Re: got a few homework questions

  #6  
Apr 15th, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Computer Science and Software Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Computer Science and Software Design Forum

All times are GMT -4. The time now is 10:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC