Mike Ash: “As anyone who does threaded programming knows, it’s difficult. Really difficult. Threaded execution results in highly unpredictable timing with how multiple threads interact with each other. The result is that code which appears to be correct and passes tests can be subtly flawed in such a way that it fails rarely and mysteriously.

There are many rules to follow when writing threaded code, but the most important one is this: lock all access to shared data.”

If you’re a Windows developer, and have had the pleasure of coding a threaded application, OSAtomic sounds pretty darned familiar, without reading Mike’s article. If your brain instantly went to InterlockedIncrement you’re not alone.

Threading can be difficult. Read what Mr. Ash has to say if you’re new to Cocoa, or new to development. Threads can be your best friend or your worst enemy.