[Overview][Constants][Types][Classes][Index] Reference for unit 'syncobjs' (#fcl)

TCriticalSection

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Critical section

Declaration

Source position: syncobjs.pp line 42

type TCriticalSection = class(TSynchroObject)

public

  procedure Acquire; override;

  

Enter the critical section

  procedure Release; override;

  

Leave the critical section

  procedure Enter;

  

Alias for Acquire

  function TryEnter;

  

Try and obtain the critical section

  procedure Leave;

  

Alias for Release

  constructor Create;

  

Create a new critical section.

  destructor Destroy; override;

  

Destroy the criticalsection instance

end;

Inheritance

TCriticalSection

  

Critical section

|

TSynchroObject

  

Abstract synchronization object

|

TObject

Description

TCriticalSection is a class wrapper around the low-level TRTLCriticalSection routines. It simply calls the RTL routines in the system unit for critical section support.

A critical section is a resource which can be owned by only 1 caller: it can be used to make sure that in a multithreaded application only 1 thread enters pieces of code protected by the critical section.

Typical usage is to protect a piece of code with the following code (MySection is a TCriticalSection instance):

// Previous code
  MySection.Acquire;
  Try
    // Protected code
  Finally
    MySection.Release;
  end;
  // Other code.

The protected code can be executed by only 1 thread at a time. This is useful for instance for list operations in multithreaded environments.

See also

Acquire

  

Enter the critical section

Release

  

Leave the critical section


Documentation generated on: May 14 2021