Locked

The Locked aspect can be used to lock access to a method or property so that it can only be entered from one thread at a time, similar to how the locking/lock keywords in Oxygene and C# can lock an individual block of code. The locking is done on the current instance or (for static members) current class. It behaves similar to Oxygene's locked member modifier.

Example:

type
  MyClass = public class
  public

    [Locked]
    method MyMethod();
    begin
      // this can only be entered from 1 thread at a time, all other threads block until the first is done.
    end;

    method MyMethod2(); locked; // same
    begin
      // this can only be entered from 1 thread at a time, all other threads block until the first is done.
    end;

  end;
public class MyClass
{
    [Locked]
    public void MyMethod() 
    {
        // this can only be entered from 1 thread at a time, all other threads block until the first is done.
    }
}
public class MyClass
{
    @Locked 
    public func MyMethod()  {
        // this can only be entered from 1 thread at a time, all other threads block until the first is done.
    }
}
public class MyClass
{
    @Locked
    public void MyMethod() {
        // this can only be entered from 1 thread at a time, all other threads block until the first is done.
    }

}

Defined in RemObjects.Elements.Cirrus.dll

Limitation on Island

Like Locking Statement and Locking Expressions in Oxygene, the Locked aspect is limited to work on Monitor classes, on Island. On the other platforms, any type can be locked on.

See Also