intermediateMultithreading & Concurrency340 of 436
What happens if a thread acquires a ReentrantLock and never calls unlock()? Why should unlock() sit in a finally block?
Tests whether you know an un-released ReentrantLock permanently starves every other thread waiting on it, since unlike synchronized blocks, it is never auto-released on exception -- so unlock() must be in finally to guarantee release regardless of how the critical section exits.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response