Operating Systems
An operating system is a system software that manages software and hardware resources and provide common services for computer programs.
Process and Threads
Concurrency and Parallelism
- Concurrency leverages on a single-core and interleaving of tasks to execute them at same time.
- Parallelism leverages on multi-core to execute different tasks at the same time.
Race Condition vs Data Race
Race Condition | Data Race |
---|---|
A flaw where the timing or order of execution affects correctness | Causes undefined behaviour |
Depends on the relative ordering of execution | Two or more threads are accessing same memory and at least one is a write |
- Use mutual exclusion to synchronise access to shared resources.
- Code that uses mutual exclusion is known as critical section.
Deadlock
- Mutual Exclusion: Holding non-shareable resource
- Resource Holding: Holding one resource while acquiring one more
- No-preemption: Cannot be de-allocated or forcefully removed
- Circular Wait: Closed Chain of dependency
Types of parallelism
In data parallelism, different threads access different parts of the same data structure at the same time.
In task parallelism, each thread specialises in one type of task.
Memory
Random Access Memory (RAM)
A volatile memory such that when the computer is on, the data is stored there and is lost when the computer is turned off. It is very expensive because the data can be quickly accessed.