Initial permit should be false.
When an interrupt is caught, you need to re-interrupt the current thread
catch (InterruptedException e) { th.interrupt(); }
because if park()
returns due to interrupt, the interrupt status should be set (see javadoc example)
After wait()
completes, normally or abruptly due to interrupt, consume the permit.
In unpark()
, if permit is already true, there's no need to notify.