Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What does the term block mean wrt computer science? I have seen it being used in multiple occassions but never understood what it means. Like blocking I/O? Googling doesn't seem to help me much.

share|improve this question
What's the context? Programming, networks or something else? – ChrisF Oct 16 '10 at 18:58
Networks and file I/O – Alfred Oct 16 '10 at 19:01
up vote 9 down vote accepted

Blocking I/O means that the program essentially asks, "Get me this data, I'll wait until its ready". This is in contrast to non-blocking I/O. There are two flavors: "Get me this data, I'm going to go do something else. Interrupt me when the data is ready.", and "Get me this data, I'm going to go do something else. I'll ask you later if you have it yet."

It's important because if a program blocks while waiting for data, it can't do things like respond to mouse clicks or repaint the screen. This is what's happening when you see a program labeled as "Not Responding" in the task manager.

share|improve this answer
It should also be mentioned that "blocking I/O" causes the program to give up it's turn for the CPU until the I/O is ready. The OS then wakes the process by delivering the requested I/O or its status. So by implementing blocking I/O programs can co-operate better on multitasking OSes such as Windows, Linux, etc. This is different than "spin-locking" which is basically a loop polling a system call or something else indicating I/O status waiting for the I/O. – LawrenceC Mar 16 '11 at 18:51

In summary it means that the process hangs (waits) until the I/O completes. This Wikipedia article covers it in passing, focussing on non-blocking I/O:

(blocking I/O would) block the progress of a program while the communication is in progress, leaving system resources idle. When a program makes many I/O operations, this means that the processor can spend almost all of its time idle waiting for I/O operations to complete

Of course, non-blocking I/O doesn't help much if the next step is to do something with that data.

share|improve this answer

Blocking is the simpler, move obvious way:

bytes =;  // Thread "blocks" or waits if there's nothing to read

You can't do a two-liner with non-blocking, since it involves setting up objects for each connection, which are then fed by a single "multiplexor" that constantly looks for the next thing that comes in. Imagine how the two approaches are different with a thousand or a million connections. You choose one or the other because of factors like:

  • Number of simultaneous connections to support
  • Average response time seen by an individual client
  • Total throughput of the server for all clients

For example, you might have a problem with blocking I/O holding several thousand connections open, one with each thread, because your system doesn't like having several thousand threads. But it turns out to be fairly complex issue. Read about how the perception has flip-flopped with Java, including the linked slide show (PDF).

share|improve this answer

In addition to indicating a form of synchronous signalling, in a programming context 'block' can also mean a section of code grouped together.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .