simshadows

Concurrency Notes

THIS PAGE IS A VERY EARLY WORK-IN-PROGRESS.

These notes on concurrency serve as a summary/refresher/reference. Some sections may be “pedagogically out of order” in order to make it more useful as a reference.

There’s a lot of overlap between concurrency and operating systems internals, so basic concurrency is often taught within an operating systems course in undergraduate university. For this page, I aim to summarize the practical core concepts of concurrency while avoiding going into too much detail about operating systems internals. I will often assume that you already have background in Linux, systems-level programming, and operating systems internals.

Synchronization Primitives

Mutex

package main

import (
    "fmt"
    "sync"
    "time"
)

var m sync.Mutex
var v int = 0

func producer() {
    for i := 0; i < 3; i++ {
        m.Lock()  // Blocks until mutex is released
        tmp := v + 1
        time.Sleep(time.Millisecond)  // Simulated "long running calculation"
        fmt.Printf("%d ", tmp)
        v = tmp
        m.Unlock()
    }
}

func main() {
    go producer()
    go producer()
    go producer()
    time.Sleep(time.Second)
    fmt.Println()
}

This will print: 1 2 3 4 5 6 7 8 9.

If you remove the mutex, it prints: 1 1 1 2 2 2 3 3 3.

TODO: Hmm maybe rewrite it in C?

Semaphore

TODO

Condition Variable

TODO

Useful Concurrency Abstractions

Thread/Process Pools

TODO: Start this!

Monitors

TODO: Start this!

Readers-Writer Lock

TODO: Start this!

Channels (Golang)

TODO: Start this!

Async/Await

Async/await isn’t really a concurrency, though it gives the illusion of it.

TODO: Actually, why isn’t async/await considered concurrency? Maybe find some proper references on it.

Concurrency Bugs

Deadlock

TODO: Start this!

Implementations: Threads and Processes

TODO: Start this!

Implementations: Inter-Process Communication (IPC)

TODO: Start this!

Lock-Free Data Structures

TODO: Start this!

Non-Blocking Algorithms

TODO: Start this!

Relevant Topics Not Covered

TODO: Anything else? It’s a very short list…

References and Acknowledgements

I used someone’s study list as a foundation for what to study. I’m not sure if they’re comfortable with me calling them out, but you know who you are! Thanks for the study list!

References: