OS//concurrency
Concurrency is the property of a program in which multiple computations make progress during overlapping periods. They need not execute at the same instant; that stronger property is parallelism.
Concurrency is the property of a program in which multiple computations make progress during overlapping periods. They need not execute at the same instant; that stronger property is parallelism.
Shared mutable state creates races because correctness begins to depend on timing rather than only on program order.
Mutexes protect invariants, while event loops serialize selected work onto one thread. Neither removes concurrency; each constrains where interleavings can occur.
One thread can be highly concurrent without any parallelism: asynchronous programming interleaves thousands of waits on a single core, which pays off when the work is I/O-bound and does nothing for arithmetic, where only parallel cores or processes help (Amdahl's law bounds how much).
The difficult bugs are often legal executions that happened in an order the programmer did not imagine. Logging can even hide them by changing timing.
Concurrency is less about doing many things at once than about controlling which observations of at once the program is allowed to expose.