3 ms·
> Threads are a broken programming model too More specifically, threads with shared mutable state. If state is never simultaneously shared and mutable then a
by dietrichepp 13y ago
> Threads are a broken programming model too
More specifically, threads with shared mutable state. If state is never simultaneously shared and mutable then a host of problems disappear.
- nostrademons 13y agoAnd even more specifically - threads with locks. Shared mutable state is okay as long as any state-swapping operations are atomic, eg. with STM or if you build up the state in one thread, switch it with an atomic pointer swap, and don't let other threads mutate the state.
- pcwalton 13y agoThreads with locks are fine as long as the compiler enforces that you take the lock before mutating the data (e.g. Rust). :)
- nostrademons 13y agoAnnotalysis can do this for C++ as well. The problem is that you need to enforce an ordering on locks to avoid deadlocks. That works fine if they're all within one module. It doesn't work at all if you have to coordinate callbacks across threads from different third-party libraries. The usual solution I've seen given for this is "Don't invoke callbacks when holding a lock." This is not a viable solution for most programs.