System.SyncObjs.TSpinLock

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

Delphi

TSpinLock = record

C++

struct DECLSPEC_DRECORD TSpinLock
{
private:
    static const unsigned ThreadTrackingDisabled = unsigned(0x80000000);
    static const int MaxWaitingThreads = int(0x7ffffffe);
    static const int WaitingThreadMask = int(0x7ffffffe);
    static const System::Int8 AnonymouslyOwned = System::Int8(0x1);
    static const System::Int8 LockAvailable = System::Int8(0x0);
    int FLock;
    bool __fastcall InternalTryEnter(unsigned Timeout);
    bool __fastcall GetIsLocked();
    bool __fastcall GetIsLockedByCurrentThread();
    bool __fastcall GetIsThreadTrackingEnabled();
    void __fastcall RemoveWaiter();
public:
    __fastcall TSpinLock(bool EnableThreadTracking);
    void __fastcall Enter();
    void __fastcall Exit(bool PublishNow = true);
    bool __fastcall TryEnter()/* overload */;
    bool __fastcall TryEnter(unsigned Timeout)/* overload */;
    bool __fastcall TryEnter(const System::Timespan::TTimeSpan &Timeout)/* overload */;
    __property bool IsLocked = {read=GetIsLocked};
    __property bool IsLockedByCurrentThread = {read=GetIsLockedByCurrentThread};
    __property bool IsThreadTrackingEnabled = {read=GetIsThreadTrackingEnabled};
    TSpinLock() {}
};

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
record
struct
public
System.SyncObjs.pas
System.SyncObjs.hpp
System.SyncObjs System.SyncObjs

Beschreibung

Instanzen von TSpinLock ermöglichen einem Thread in einer Multithread-Anwendung, temporär eine Sperre zu übernehmen und dabei andere aufrufende Threads nicht zu blockieren.

Mit TSpinLock implementieren Sie eine einfache Sperre, in die nicht wieder eingetreten werden kann. Diese Sperre blockiert aufrufende Threads nicht, die ein Synchronisierungsobjekt verwenden. Stattdessen werden einige zusätzliche CPU-Zyklen ausgeführt und gewartet, bis die Sperre freigegeben wird.

Durch die Verwendung von TSpinLock anstelle einer Methode zum Wechseln des Threads wird die Verarbeitungsgeschwindigkeit erhöht, wenn die Dauer, für die die Sperre aufrechterhalten wird, sehr kurz ist (wenige CPU-Zyklen).

Die wartenden Threads blockieren jedoch nicht die Ausführung von Threads mit einer höheren Priorität.

Siehe auch