System.SyncObjs.TSpinLock

De RAD Studio API Documentation
Aller à : navigation, rechercher

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() {}
};

Propriétés

Type Visibilité  Source Unité  Parent
record
struct
public
System.SyncObjs.pas
System.SyncObjs.hpp
System.SyncObjs System.SyncObjs

Description

Les instances de TSpinLock permettent à un thread d'une application multithread d'acquérir temporairement un verrou sans bloquer les autres threads appelants.

Utilisez TSpinLock pour implémenter un simple verrou tournant non-réentrant. Ce verrou ne bloque pas les threads appelants avec un objet de synchronisation. A la place, il consomme quelques cycles CPU supplémentaires et attend la libération du verrou.

L'utilisation de TSpinLock, au lieu d'un thread permutant des méthodes, augmente la vitesse de traitement si le temps de verrouillage est très court (de l'ordre de quelques cycles CPU).

Toutefois, puisque la CPU est cédée, les threads en attente ne bloqueront pas le traitement des threads de priorité supérieure.

Voir aussi