Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain blocking and unblocking 1

Status
Not open for further replies.

Jaheel22

Technical User
Jul 14, 2004
84
US
Would you please write few lines on the concept of blocking / unblocking ? There was an interveiw question to explain blocking/unblocking.

I googled but could not find the answer.

Thanks so much.
 
Basically, it means whether or not your current thread waits for something. Most usually an issue with GUIs. Consider the following:

Your user hits the 'export' button. Assume 'export' is a function that does a lot of computation and disk I/O, which for a processor that can handle 2 gig of instructions per second is classed as a 'slow' operation. If you made a blocking (synchronous) call to the export method, your application would wait until it had finished before unlocking to allow the user to do something else. For a GUI, this can mean that the user is locked out for the duration.

With a non-blocking (asynchronous) call, you are effectively saying "Start this operation now, but as I have two billion things I can be doing in the next second, I won't wait. Just notify me when it's completed." You can then continue processing, and check later to see if the operation has completed.

Does this help?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Steve

I really thank you for your answer to my question.
Yes, indeed, it does help.

Thanks again.
 
Just for future reference in terms of locking - BitStreams also have a locking feature so that only your code can work on the stream until unlocked.

So take an image for example. You would open the image and when you are about to make a change to it (brightness or contrast etc) you would lock the bits, make your modifications and then unlock the image so that 2 people aren't applying different transformations at the same time.

You can imagine the horror of someone applying a brightness filter on an image while someone else is applying a color filter. You would have a screwed up looking image.

Thread locking is similar in nature.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top