package ru.job4j.multithreading.wait_notify_notifyall;

public class Lock {

    public volatile boolean locked = false;
    private final Object lock = new Object();
    private Thread threadLock = null;

    public void lock() throws InterruptedException{
        synchronized (lock) {
            while(locked && threadLock != Thread.currentThread()) {
                lock.wait();
            }
            locked = true;
            threadLock = Thread.currentThread();
        }

    }

    public void unlock() throws InterruptedException {
        if (Thread.currentThread() == threadLock) {
            synchronized (lock) {
                locked = false;
                lock.notifyAll();
            }
        }
    }
}

@@ -541,16 +541,46 @@
 ption %7B%0A
+        synchronized (lock) %7B%0A
         
@@ -627,42 +627,8 @@
 ) %7B%0A
-            synchronized (lock) %7B%0A
     

task 1100