package ru.job4j.wait;


/**
 * Class <Name class>.
 *
 * @author Alexey Rastorguev (rastorguev00@gmail.com)
 * @version 0.1
 * @since 11.02.2018
 */
public class SimpleLock {
    private boolean block = false;
    private Thread lockThred = null;
    private int lockCount = 0;

    public void lock() {
        Thread curThread = Thread.currentThread();
        while (block && lockThred != curThread) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        block = true;
        lockCount++;
        lockThred = curThread;
    }

    public void unlock() {
        if (Thread.currentThread() == this.lockThred) {
            lockCount--;
        }
        if (lockCount == 0) {
            block = false;
            notify();
        }
    }

}

@@ -181,16 +181,25 @@
 private 
+volatile 
 boolean 
@@ -225,16 +225,25 @@
 private 
+volatile 
 Thread l
@@ -271,16 +271,25 @@
 private 
+volatile 
 int lock
@@ -307,24 +307,37 @@
 %0A    public 
+synchronized 
 void lock() 
@@ -681,16 +681,29 @@
  public 
+synchronized 
 void unl

modify SimpleLock [task #1100]