Withdrawn: In rare cases, the unlock() on join() might fail, causing an IllegalMonitorStateException
Alan Bateman
alanb at openjdk.java.net
Sat Mar 5 17:50:25 UTC 2022
On Thu, 25 Feb 2021 11:10:41 GMT, kabutz <duke at openjdk.java.net> wrote:
> Unlike synchronized/wait, the Condition.await() method does not necessarily reacquire the lock on exit, for example if the thread is stopped or if CTRL+C is caused in jshell. In that case we would enter the finally block without the lock held and unlocking would cause an IllegalMonitorStateException.
>
> For example, run the following code from jshell and then press CTRL+C:
>
>
> Object monitor = new Object();
> for (int i = 0; i < 10_000; i++) {
> Thread.startVirtualThread(() -> {
> synchronized (monitor) {
> try {
> monitor.wait();
> } catch (InterruptedException ignore) {}
> }
> });
> }
> Thread.startVirtualThread(() -> System.out.println("done")).join();
>
>
> Output is:
>
>
> | Exception java.lang.IllegalMonitorStateException
> | at ReentrantLock$Sync.tryRelease (ReentrantLock.java:175)
> | at AbstractQueuedSynchronizer.release (AbstractQueuedSynchronizer.java:1007)
> | at ReentrantLock.unlock (ReentrantLock.java:494)
> | at VirtualThread.joinNanos (VirtualThread.java:635)
> | at Thread.join (Thread.java:2281)
> | at Thread.join (Thread.java:2366)
> | at (#3:1)
This pull request has been closed without being integrated.
-------------
PR: https://git.openjdk.java.net/loom/pull/32
More information about the loom-dev
mailing list