# Processes and Threads: Multithreading

## Metadata
- Author: [[codecademy.com]]
- Full Title: Processes and Threads: Multithreading
- Category: #articles
- Summary: A CPU core can run only one thread at a time, but blocking and context switching make tasks appear simultaneous. Modern cores can run multiple threads (multithreading), which improves performance and responsiveness by splitting work. Multithreading adds complexity and risks like data races and deadlocks, making programs harder to write and test.
- URL: https://www.codecademy.com/courses/fundamentals-of-operating-systems/lessons/os-processes-and-threads/exercises/multithreading
## Highlights
- With some hardware advances, single CPU cores can now execute multiple threads at once, which is a capability called *multithreading*. ([View Highlight](https://read.readwise.io/read/01k6re7wmkjc5pwfjtvc47ns28))
- Parallelizing computations have a variety of benefits, such as improved system utilization and system responsiveness. This is because tasks can be more evenly split between multiple threads, exhausting all available computing resources ([View Highlight](https://read.readwise.io/read/01k6re8x2x0p23s48b8s9xewt7))
- However, these optimizations come with disadvantages due to the additional complexity required for the implementation. Not only are these programs more difficult to write because of their non-sequential nature, but they also create whole new classes of bugs. ([View Highlight](https://read.readwise.io/read/01k6re9gwakxk38hxpwzcrm4f9))
- The two of the most common examples are data races, where multiple threads attempt to modify the same piece of data, and deadlocks, where multiple threads all attempt to wait for each other and freeze the system. ([View Highlight](https://read.readwise.io/read/01k6rea6hc4bds2p7934nb541d))
- Also, since these bugs are usually related to the tight timing of CPU interactions, the programs can be considered non-deterministic and therefore untestable, compounding the problem. ([View Highlight](https://read.readwise.io/read/01k6reahj83n85wa8d74h7wv70))