Locking Objects

From RAD Studio
Jump to: navigation, search

Go Up to Avoiding Simultaneous Access

Some objects have built-in locking that prevents the execution of other threads from using that object instance.

For example, canvas objects (TCanvas and descendants) have a Lock method that prevents other threads from accessing the canvas until the Unlock method is called.

VCL applications also include a thread-safe list object, System.Classes.TThreadList. Calling LockList returns the list object while also blocking other execution threads from using the list until the UnlockList method is called. Calls to TCanvas.Lock or TThreadList.LockList can be safely nested. The lock is not released until the last locking call is matched with a corresponding unlock call in the same thread.

See Also