For the More Curious: Race Conditions
Whenever you are running code in parallel, you need to be aware of race conditions. A race condition is a scenario in which your program behaves incorrectly when instructions execute at an unexpected time or in an unexpected order.
To see a race condition in action, imagine a booking system that would like to efficiently check in its passengers and count the number of passengers it has processed. If there are 1,000 flights with 75 passengers each, you might decide to use a separate coroutine to process each flight’s 75 passengers. To implement this, you can write code that looks like this. Try it in the REPL.
(When you launch the REPL, you will have the choice of launching it in the context of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access