Mercurial
view asyncio_threads/bank_question/README.md @ 265:056790c4fb0d
add role-aware Epi assistant prompts
Add verified June knowledge, guest/member/admin Copilot profiles, profile-isolated session recovery, animated Epi greetings, and a single authoritative runtime config workflow for inference.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 07 Aug 2026 10:50:30 -0700 |
| parents | 46daba6e3cf4 |
| children |
line wrap: on
line source
# Bank Account You are given a simplified multi-threaded “bank account” implementation used by one of our infrastructure teams. The current code processes deposits concurrently but produces incorrect results. ``` class BankAccount: def __init__(self, balance): self.balance = balance def deposit(self, amount): new_balance = self.balance + amount # read time.sleep(0.1) # simulate delay self.balance = new_balance # write account = BankAccount(0) with ThreadPoolExecutor(max_workers=2) as executor: futures = [ executor.submit(account.deposit, 500), executor.submit(account.deposit, 700), ] ``` Task Identify the concurrency bugs in the implementation. Explain why these bugs occur. Fix the implementation without modifying the existing BankAccount class directly. You may use subclassing (Python) or embedding (Go-style composition), depending on the language you choose. Ensure your solution is thread-safe and produces the correct final balance (1200).