• Yet more precision about my inventions that are my SemaMonitor and Sema

    From Wisdom91@21:1/5 to All on Sat Jun 27 11:59:22 2020

    Yet more precision about my inventions that are my SemaMonitor and
    SemaCondvar and my Monitor..

    My inventions that are my SemaMonitor and SemaCondvar are fast pathed
    when the count of my SemaMonitor or my SemaCondvar is greater than 0, so
    in this case the wait() method stays on the user mode and it doesn't
    switch from user mode to kernel mode that costs around 1500 CPU cycles
    and that is expensive, the signal() method is also fast pathed when
    there is no item in the queue and count is less than MaximumCount, read
    here about what is the cost (in CPU cycles) to switch between windows
    user mode and kernel mode:


    You can read about and download my inventions of SemaMonitor and
    SemaCondvar from here:


    And the light weight version is here:


    And i have implemented an efficient Monitor over my SemaCondvar.

    Here is the description of my efficient Monitor inside the Monitor.pas
    file that you will find inside the zip file:


    This is my implementation of a Monitor over my SemaCondvar.

    You will find the Monitor class inside the Monitor.pas file inside the
    zip file.

    When you set the first parameter of the constructor to true, the signal
    will not be lost if the threads are not waiting with wait() method, but
    when you set the first parameter of the construtor to false, if the
    threads are not waiting with the wait() method, the signal will be lost..

    Second parameter of the constructor is the kind of Lock, you can set it
    to ctMLock to use my scalable node based lock called MLock, or you can
    set it to ctMutex to use a Mutex or you can set it to ctCriticalSection
    to use the TCriticalSection.

    Here is the methods of my efficient Monitor that i have implemented:

    TMonitor = class


    constructor Create(bool:boolean=true;lock:TMyLocks=ctMLock);
    destructor Destroy; override;
    procedure Enter();
    procedure Leave();
    function Signal():boolean;overload;
    function Signal(nbr:long;var remains:long):boolean;overload;
    procedure Signal_All();
    function Wait(const AMilliseconds:longword=INFINITE): boolean;
    function WaitersBlocked():long;


    The wait() method is for the threads to wait on the Monitor object for
    the signal to be signaled. If wait() fails, that can be that the number
    of waiters is greater than high(longword).

    And the signal() method will signal one time a waiting thread on the
    Monitor object, but if signal() fails , the returned value is false.

    the signal_all() method will signal all the waiting threads on
    the Monitor object.

    The signal(nbr:long;var remains:long) method will signal nbr of
    waiting threads, but if signal() fails, the remaining number of signals
    that were not signaled will be returned in the remains variable.

    and WaitersBlocked() will return the number of waiting threads on
    the Monitor object.

    and Enter() and Leave() methods to enter and leave the monitor's Lock.

    You can download the zip files from:


    and the lightweight version is here:


    Thank you,
    Amine Moulay Ramdane.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)