1. CPU-bound and I/O bound
- I/O-bound, async libraries available → async. Highest concurrency per unit of memory.
- I/O-bound, blocking libraries → threads. A thread blocked on a socket costs a stack, not a core.
- CPU-bound → processes. Threads will not help in Python, and in any language CPU work needs real cores.
2. Synchronize Primitives
- Mutex
- Semaphore
- Read-write lock
- Conditional lock
- Atomic operations: hard-ware level than mutex.
- Queue
3. Deadlock and Starvation
4. Question
🔴 "Two API requests both try to buy the last item in stock. How do you prevent overselling?"