# Concurrency and Multi-Threading Demystified

- Speaker: [Haim Yadid](/wiki/speakers/haim-yadid.md)
- Event: [Reversim Summit 2014](/wiki/years/2014.md)
- Video: https://www.youtube.com/watch?v=haJp9GxLzOE
- Transcript: [/transcripts/2014/46-haJp9GxLzOE.md](/transcripts/2014/46-haJp9GxLzOE.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Distributed Systems](/wiki/topics/distributed-systems.md), [Architecture](/wiki/topics/architecture.md), [Functional Programming](/wiki/topics/functional-programming.md), [Performance](/wiki/topics/performance.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker demystifies the complex world of concurrency and multi-threading in software engineering by breaking down core terminology, execution models, and state management strategies. The talk explores common pitfalls like liveness issues, data races, and performance bottlenecks, while comparing different architectural approaches. Finally, the audience learns how to design robust concurrent systems using lightweight threads, immutability, and transactional memory.

## Key points

- [1:18](https://www.youtube.com/watch?v=haJp9GxLzOE&t=78s) Hardware evolution has shifted towards multi-core processors, making concurrency and parallel execution mandatory for modern software performance.
- [2:20](https://www.youtube.com/watch?v=haJp9GxLzOE&t=140s) Concurrency is an architectural design process that decomposes an application into independently running components, distinct from parallel execution.
- [4:21](https://www.youtube.com/watch?v=haJp9GxLzOE&t=261s) Concurrent applications face severe liveness and deadlock issues when processes block or interfere with each other.
- [6:31](https://www.youtube.com/watch?v=haJp9GxLzOE&t=391s) Data races occur when multiple threads simultaneously access and modify the same memory region, leading to corrupted data and application crashes.
- [11:19](https://www.youtube.com/watch?v=haJp9GxLzOE&t=679s) Execution models require choosing between heavy-weight threads and lightweight green threads or actors for better resource management.
- [21:56](https://www.youtube.com/watch?v=haJp9GxLzOE&t=1316s) Managing application state safely involves three main strategies: shared mutability, pure immutability, and isolated mutability.
- [28:23](https://www.youtube.com/watch?v=haJp9GxLzOE&t=1703s) Software Transactional Memory (STM) provides an optimistic concurrency approach to update in-memory state without the risks of traditional locks.
- [39:01](https://www.youtube.com/watch?v=haJp9GxLzOE&t=2341s) Isolated mutability through actor models allows independent workers to communicate strictly via messages without sharing mutable state.

## Takeaways

- Design applications with decoupled components that can execute independently rather than relying solely on raw hardware scaling.
- Be cautious of shared mutability and use synchronization mechanisms, volatile keywords, or thread-safe collections when threads access common data.
- Consider adopting alternative concurrency models like Software Transactional Memory (STM) or actor-based frameworks to avoid deadlocks.
- Isolate state using actors or message-passing channels to simplify multi-threaded architectures.

## Questions this talk answers

- How can I prevent deadlocks and data races when multiple threads access shared data structures?
- What is the difference between heavy-weight threads and lightweight green threads, and when should I use each?
- How does Software Transactional Memory (STM) compare to traditional pessimistic locking?

## Technologies

Java, Go, Scala, Clojure

## Tags

actors, architecture, concurrency, data races, immutability, multi-threading, performance
