Thread safety and deadlocks, explained and demonstrated
A fast concepts round. What makes code thread-safe? Show the common ways a deadlock happens (for example two threads taking two locks in opposite order) and the ways to prevent each: lock ordering, timeouts, fewer locks. Some interviewers ask you to write a deadlock on purpose and then fix it. Short follow-ups compare arrays and linked lists for access, insertion and memory.
No answer yet. Write the first one; the best answer gets endorsed.
