Skip to content

Instantly share code, notes, and snippets.

View danog's full-sized avatar
🇺🇦
#StandWithUkraine

Daniil Gentili danog

🇺🇦
#StandWithUkraine
View GitHub Profile
@danog
danog / concurrency.md
Created January 5, 2024 01:20
An overview of concurrency and parallelism

Sorry if I'm stating the obvious for some, but I feel like many people are lacking a good comprehension of what is concurrency vs parallelism, and since Operating Systems was my favorite uni exam decided to write up a small refresher, a few years after finishing it :D

Put (very) simply, a scheduler is a piece of software that schedules execution of some code on the CPU.

The OS scheduler is a preemptive scheduler that runs in the kernel and schedules OS threads for execution on the CPU.

Since there are usually many threads waiting for CPU time, and only one CPU (let's consider just single-core systems), the scheduler gives each thread a little time slice, and once that expires, it interrupts execution of the thread starts thr next one in the queue. Only one thread is physically running at any given moment, and the entire set of all active threads is considered to be running concurrently.

The ability to interrupt execution of threads even if they don't explicitly return control to the scheduler (such as by