Thread safety check of MemorySegment

Uwe Schindler uschindler at apache.org
Tue Jul 21 20:01:39 UTC 2020


Hi,

Why does it not work for mapped segments, is this a bug? I was about to test this for Lucene...

Anyways, in which JDK will the current code be part of? 15 or 16?

Uwe

Am July 21, 2020 5:49:46 PM UTC schrieb Maurizio Cimadamore <maurizio.cimadamore at oracle.com>:
>
>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