Locked (keyword)

From RemObjects Software

Jump to: navigation, search

This is a Oxygene Keyword topic
Feel free to add your notes to this topic below.



The locked directive allows methods to be declared implicitly thread safe. The compiler will automatically generate the proper calls to Monitor surrounding the method body.

method DoItSafely; locked;

Declaring a method as "locked" is basically equivalent to surrounding the entire method body with a "locking" statement:

locking self do begin
  ...
end;

Applies to


Locked On

In version 3 (new in Oxygene 3.0), it's possible to enter the object to lock a method, property or event on. The syntax for this is:

method DoItSafely; locked on fLockObject;


Notes

Locked is only allowed on non-virtual and final methods. Locked operates at the class level, so methods will lock each other.

See the Microsoft documentation on Monitor Class for further information regarding locking. Their docs state:

"The Monitor class controls access to objects by granting a lock for an object to a single thread. Object locks provide the ability to restrict access to a block of code, commonly called a critical section. While a thread owns the lock for an object, no other thread can acquire that lock. You can also use Monitor to ensure that no other thread is allowed to access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object."


See Also


Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0 Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)

GlossaryKeywordsLanguage FeaturesPlatform FeaturesSamplesArticlesHow ToIssues

Personal tools