public void run() {
        while(true) {
            for (int i = 0; i < 4; i++) {
                semaphore.take();
                System.out.println(threadIndex + ": " + i);
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            semaphore.give();
            semaphore.give();
            semaphore.give();
            semaphore.give();
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }