package threaddemo.lock;

public class CLHDemo {

    public static void main(String[] args) throws InterruptedException {
        CLH clh = new CLH();
        Thread t1 = new Thread(() -> {
            System.out.println("t1 start");
            clh.lock();
            try {
                System.out.println("t1 get lock");
                Thread.sleep(1000L);
                System.out.println("t1 release lock");
                clh.unlock();
                System.out.println("t1 end");
            } catch (InterruptedException e) {
                throw new RuntimeException("interrupted");
            }
         });
        t1.start();
        Thread.sleep(10L);

        Thread t2 = new Thread(() -> {
            System.out.println("t2 start");
            clh.lock();
            System.out.println("t2 get lock");
            clh.unlock();
            System.out.println("t2 release lock");
            System.out.println("t2 end");
        });
        t2.start();
        t1.join();
        t2.join();
        System.out.println("main end");
    }
}
