Getting Stuck: The Threads That Wouldn’t Behave Concurrency has always fascinated me. The idea that multiple tasks can run “simultaneously” — or at least give the illusion of simultaneity — feels like wizardry. But when I tried to actually implement something non-trivial, I got stuck in ways I never expected. The Task I wanted to simulate a bank with multiple accounts. Each account supports deposit and withdrawal. Multiple users (threads) perform transactions at the same time. Sounds simple. Attempt 1: Naive Multithreading I started with Python’s threading module: import threading class Account: def __init__(self, balance=0): self.balance = balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): if self.balance >= amount: self.balance -= amount return True return False account = Account(100) def transaction(): for _ in range(1000): account.depo...
A curious mind exploring the beautiful world