-
Book Overview & Buying
-
Table Of Contents
Systems Programming with Zig
By :
We briefly talked about threads in the previous chapter. However, in this chapter, we are going to discuss concurrency in more detail, which in practice means working and synchronizing multiple threads, avoiding race conditions and deadlocks, collecting results from multiple threads, and implementing concurrent patterns such as Consumer-Producer, Thread Pool, and Ring Buffer with the help of mutexes, atomic operations, and condition variables. Although threads can, in theory, take advantage of multiple processors or cores, it is not always that simple or straightforward. It is a common misconception that concurrency and parallelism are the same thing, which is far from the truth! Concurrency is a way of structuring components so that they can be independently executed without issues, when possible, whereas parallelism is the simultaneous execution of multiple things. Having lots of threads waiting for a shared resource and doing...