Thread safety check of MemorySegment

NekoCaffeine nekocaffeine at qq.com
Tue Jul 21 18:17:41 UTC 2020


Really glad to receive your response.


I read the latest code, and my MemorySegment is obtained through MemorySegment::mapFromPath.
In MemorySegment::ofNativeRestricted, cleanup is required as a parameter. Is there any way I can get this Runnable?


As far as I know, MemoryScope is an internal object, and cleanup is the cleanupAction field of MemoryScope.Root.
In my opinion, it may be possible to make the newOwner parameter in the withOwnerThread method null, or provide a new equivalent method to reset the owner thread.


Thanks,


NekoCaffeine


> 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