public synchronized void unlock() {
        if (ASSERTS && owner != Thread.currentThread()) {
            Thread.dumpStack();
            throw new IllegalLockStateException("Don't own monitor");
        }

        locked = false;
        if (waiters > 0) {
            if (STATISTICS) {
                unlock_waiting++;
                unlock_waiters += waiters;
            }

            if (!PRIORITY || prio_waiters == waiters) {
                if (STATISTICS) {
                    unlock_waiting++;
                }
                // either no prio -> wake up anybody
                // or prio and only prio waiters -> wake up a prio waiter
                notify();
            } else {
                // Sorry, there are prio and nonprio waiters. To be sure a
                // prio waiter comes alive, we have no choice but to wake all.
                if (STATISTICS) {
                    unlock_bcast++;
                }
                notifyAll();
            }
        }

        if (ASSERTS) {
            owner = null;
        }
    }