educative.io

Educative

Could not understand the use of demsWaiting.acquire() and repubsWaiting.acquire()

What will happen if we switch the statements lock.unlock() demsWaiting.acquire() line 50 and 51


Type your question above this line.

Course: https://www.educative.io/collection/5307417243942912/5707702298738688
Lesson: https://www.educative.io/collection/page/5307417243942912/5707702298738688/5653164804014080

so we have set the permit for semaphore as 0, which means when we do semaphore.acquire our code is going to wait for the permits to be available.
so if we do lock.unlock() after acquire then it wont release the lock and other wont be able to enter the lock and hence deadlock will occur.


Course: Java Multithreading for Senior Engineering Interviews - Learn Interactively
Lesson: Uber Ride Problem - Java Multithreading for Senior Engineering Interviews