Thread safety check of MemorySegment
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Jul 21 17:49:46 UTC 2020
On 21/07/2020 15:03, Maurizio Cimadamore wrote:
> If you have a MemoryAddress and want to create an unsafe segment from
> it which is not confined, you can use the
> MemorySegment::ofNativeRestricted factory, at least as a temporary
> workaround. Doesn't work (as pointed out earlier in this mailing list)
> if you are after mapped segments, but for plain native segments should
> work fine.
>
> E.g.
>
> MemorySegment segment = MemorySegment.allocateNative(100);
>
> MemorySegment unconfined =
> MemorySegment.ofNativeRestricted(segment.baseAddress(), 100, null,
> null, null);
>
> // from now on, just use unconfined
>
> Maurizio
>
> On 21/07/2020 14:54, 虾米Mickey wrote:
>> Hi, I am using foreign to develop indie games.
>> A library called bgfx is used.
>>
>> There is a function,
>> https://bkaradzic.github.io/bgfx/bgfx.html#_CPPv4N4bgfx7makeRefEPKv8uint32_t9ReleaseFnPv
>> There is a clear requirement for the incoming memory release
>> callback: ReleaseFn function must be able to be called from any thread.
>>
>> Due to MemorySegmentImpl::close ->
>> MemorySegmentImpl::checkValidState, this will result in
>> IllegalStateException("Attempt to access segment outside owning thread")
>>
>> Currently I release the memory through segment.scope().close(), of
>> course this is not a direct call.
>> Should there be a more direct way to release operations under unsafe
>> conditions?
>>
>> Thanks and regards,
>>
>> NekoCaffeine
More information about the panama-dev
mailing list