What are threads?

And what problem do they solve in programming? Each thread has its own “stack”. Why problem were operating system threads initially designed to solve?

Initially it is just the fact that CPUs are much much much faster than input/output (I/O) which is much much slower. Operating system threads allow the CPU to used to many different things while waiting for slow I/O.

As CPU technology has progressed, CPU manufacturers have introduced the idea of ‘cores’ which means that these CPUs can executed in parallel on these cores. So architecting high performance software today means understanding these problems very well.

See blocking versus non blocking calls.