0Pricing
C Academy · Lesson

Blocking vs Non-Blocking I/O

Why event loops matter.

What Blocking Means

A blocking system call suspends the calling thread until the operation can proceed. When you call recv() on a socket with no data, the kernel parks your thread until bytes arrive.

This is simple to reason about: one connection, one thread, straight-line code. The cost shows up when you need to serve thousands of clients at once.

ssize_t n = recv(fd, buf, sizeof buf, 0);
/* thread sleeps here until data or error */
if (n > 0) handle(buf, n);

The Scaling Problem

With blocking I/O, one stuck client blocks the whole thread. The classic fix is one thread (or process) per connection.

That works to a point, but 10,000 threads means 10,000 stacks, heavy context switching, and scheduler overhead. This is the famous C10k problem that pushed servers toward event-driven designs.

All lessons in this course

  1. Blocking vs Non-Blocking I/O
  2. Setting Up epoll
  3. The Event Loop
  4. A Simple Echo Server
← Back to C Academy