Concurrency and atomicity

Concurrent execution implies that multiple threads can run truly in parallel on multiple CPU cores. When this happens on text (code), it's good; we get higher throughput. However, the moment we run concurrently while working on shared writable data, we will have a problem with data integrity. This is because text is read-only (and executable), whereas data is read-write.

What we would really like, of course, is to be greedy and have the best of both worlds: execute code concurrently via multiple threads, but the moment we must work on shared data, stop the concurrency (parallelism), and have just one thread run through the data section sequentially until it's done, then resume parallel execution.

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.