MemorySegment.close(), threads
Michael Zucchi
notzed at gmail.com
Fri Jan 17 06:58:46 UTC 2020
On 16/1/20 10:06 pm, Maurizio Cimadamore wrote:
>
> Related to your issue with freeing upcall stubs, Jorn and I discussed
> this yesterday and came up with an idea which, I think, should address
> your concerns. Basically, the idea is:
>
> * upcall stub address are based on the Nothing segment; as such they
> can be passed opaquely, cannot be dereferenced, cannot be closed
> * SystemABI will provide an extra method to explicitly *free* an
> upcall stub (rather than relying on the closure of the segment
> associated with it)
>
> I think this will work much better, and will not feature the same
> restrictions you have when using upcalls from multiple threads.
>
> Also note that, by using this mechanism, you could, if you wanted,
> register the upcall MemoryAddress onto a Cleaner, so that the
> 'freeUpcallStub' method would be called by the GC when the upcall
> stub address is no longer reachable, if you wish to leave things to
> the GC.
>
Ok that sounds reasonable to me, although it's always nice(r) when
things are orthogonal it's not always practical. Not being able to
dereference the contents makes sense though.
For what it's worth I've worked out all the main mechanisms to do what i
need based on the low-level api but I haven't tried applying it to a
real library as it will take some work. I needed a Pointer<> type but
i'm trying to avoid needing it for every C pointer since the only real
difference between a struct and a pointer to a struct is how a function
accepts and returns them, and it knows which mode to use (and arrays,
likewise). I'm hoping it will work for me if not in general.
Michael
More information about the panama-dev
mailing list