You’ve used a mutex before, but have you wondered how it works? In this class, we look inside to discover what lock and unlock do. We’ll discuss how a program coordinates with the operating system, to allow multiple threads to synchronize their work.
Aside from satisfying your curiosity, this knowledge improves your understanding of concurrent processing. Anybody working with parallel computing should know what’s happening. It helps you spot defects, unravel performance problems, and avoid the evil data races.
I might gloss over a few details in the class, but at the end you’ll understand how a mutex works.
How would you like to write a mutex?
That may sound harder than it really is. I’ve created a small app, with some skeleton interface for the mutex. You need to complete the mutex to get the simulation working correctly.
This exercise helps you internalize a part of how the mutex works.
The code is at: https://github.com/mortoray/interview.codes
Check it out and open the `demo.html` file in your browser. You need to complete the `mutex.js` file.