IllegalStateException when attempting to transfer MemorySegment thread ownership
Ty Young
youngty1997 at gmail.com
Mon Jul 20 07:59:40 UTC 2020
When attempting to transfer thread ownership of a MappedMemorySegment,
an IllegalStateException is thrown:
java.lang.IllegalStateException: Attempted access outside owning thread
with the following code:
MappedMemorySegment segment;
System.out.println("Owner: " + this.address.segment().ownerThread());
System.out.println("Current: " + Thread.currentThread());
if(this.address.segment().ownerThread().equals(Thread.currentThread()))
segment = (MappedMemorySegment)this.getAddress().segment();
else
segment =
(MappedMemorySegment)this.getAddress().segment().withOwnerThread(Thread.currentThread());
This error happens when closing my JavaFX application via its close
handler on the above else branch. The application calls a static method
which eventually creates the MappedMemorySegment on the main thread but
the close handler works on the JavaFX thread as shown from the print output:
Owner: Thread[main,5,main]
Current: Thread[JavaFX Application Thread,5,main]
I tried using unsafe MemorySegment.ofNativeRestricted to make the
segment thread independent, but it doesn't work out due to
MemorySegment.ofNativeRestricted always returning a pure
MemorySegmentImpl implementation instead of the
**Mapped**MemorySegmentImpl. I'm guessing this is a bug?
More information about the panama-dev
mailing list