O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Critical sections

How do we fix the preceding race? It's quite straightforward, really: we have to ensure that, as stated earlier, the banking operationsdeposits, withdrawals, and so onare guaranteed to do two things:

  • Be the only thread running the code at that point in time
  • Be atomic — run to completion, without interruption

Once this is achieved, the shared data will be safe from corruption. The section of code that must run in the fashion described previously is called a critical section.

In our fictional banking application, the threads running the code to perform a banking operation (a deposit or a withdrawal) must do so in a critical section, shown as follows:

Figure 3: The critical section

So, now, let's say that the banking application ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required