Consider the following program:
import java.util.concurrent.locks.*; public class Main { public static void main(String []args) { Lock lock = new ReentrantLock(); try { System.out.print("Lock 1 "); lock.lock();//from w ww. j a v a2 s. c om System.out.print("Critical section 1 "); System.out.print("Lock 2 "); lock.lock(); // LOCK_2 System.out.print("Critical section 2 "); } finally { lock.unlock(); System.out.print("Unlock 2 "); lock.unlock(); // UNLOCK_1 System.out.print("Unlock 1 "); } } }
Which one of the following options is correct?
d)
In a re-entrant lock, you can acquire the same lock again.
However, you need to release that lock the same number of times.