__lock (object type)

I’m sharing Silver code between my Cocoa shared library and my Island (Windows) DLL. I’m using the __lock keyword to protect a collection from concurrent access. In the Cocoa project, I was locking on a plain Object variable:

let someLock = Object()

However, this was causing build errors in the Island project:

Type mismatch, expected “RemObjects.Elements.System.Monitor!”

I therefore changed the object initialization to:

let someLock = Monitor()

Is this to be expected? I understand some parts of the documentation are not up to date but this surprised me.

Thanks.

-Benoît

Yeah, iirc __lock() is limited to be used on Monitor types, on Island; it’s a limitation of the Island runtime.

Essentially it comes down to tradeoffs. If we support locking any object we’ll need to add a pointer sized block of memory to every single object. Even if it’s never used as a monitor. Instead we only allow it on monitor for monitoring purposes.

2 Likes