Knock, knock. Race condition! Who's there? - A Refactoring Story

by Stefan Baumgartner

Concurrency in Rust can be hard, especially when the language throws other obstacles in your way. Like with this request that found me one day. What started as a humble ask to remove some indentation and nesting turned into a crime scene of concurrency gone wrong. Innocent memory being shared across tasks. A supervision task that made everything worse. A race condition waiting to strike.

In this talk, we will apply refactoring techniques that address structure, ownership, and readability, while simultaneously making the actual problem visible.

We’ll solve the emerging concurrency problem by identifying what we actually want to accomplish, then turn everything upside down. In doing so, we’ll rediscover proven patterns for async programming that predate async Rust but remain relevant today.

Picture of Stefan Baumgartner

Stefan Baumgartner

he/him
oida.dev
Links: icon of linkedin icon of bluesky

Stefan Baumgartner is an architect and developer based in Austria. He is the author of “TypeScript in 50 Lessons” (Smashing Magazine, 2020) and “The TypeScript Cookbook” (O’Reilly, 2023). In his spare time, he organizes ScriptConf and Rust Linz. Stefan enjoys Italian food, Belgian beer, and British vinyl records.