For example, in a multithreaded software, two separate threads might access a common variable.

This will cause undesirable results.

How a Processor Switches Processes

Modern operating systemscan run more than one process simultaneously, called multitasking.

A view from above of somebody typing on a laptop with a Python book alongside them

The CPU may interrupt a process before it has completed, and resume a different process.

The operating system controls the management of these processes.

For example, this could be a period of two microseconds.

A diagram showing 3 queued, sleeping processes an 1 active process that the CPU is currently running

The CPU takes each process in turn and executes commands that will run for two microseconds.

It then continues to the next process, regardless of whether the current one has finished or not.

However, when you look behind the scenes, the CPU is still doing things in order.

As a result, it is a rather rudimentary method that is rarely used in real systems.

Now, to understand all this better, imagine that two threads are running.

If the threads access a common variable, a race condition may arise.

The purpose of this system is to manage money transactions that will take place on the web.

You have now created an account with a balance of $5,000.

This utility can perform the following operations with GET request links.

Since Flask runs on the 5000 port by default, the address you access it on is127.0.0.1:5000/.

Probability of a Race Condition Vulnerability

The above web tool contains a possible race condition vulnerability.

Imagine you have $5,000 to start with and create two different HTTP requests that will send $1.

For this, you’re free to send two different HTTP requests to the link127.0.0.1:5000/send/1.

The example above was for a simple money transfer utility.

Imagine working on a software project that manages a bank account or the backend of a large e-commerce site.

This requires a strong responsibility.

A race condition vulnerability is only one of them.

One of the most important skills you might acquire as a programmer is familiarity with software security.