Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I have updated my SemaCondVar to version 1.15

3 views
Skip to first unread message

aminer

unread,
Nov 21, 2013, 3:18:01 PM11/21/13
to

Hello,


I have updated my SemaCondVar to version 1.15, i have avoided
the windows critical section and replaced it with a FIFO fair lock
so that it becomes starvation free...

SemaCondvar version 1.15

Author: Amine Moulay Ramdane.

Description:

SemaCondvar and SemaMonitor are new and portable synchronization objects
, SemaCondvar combines all the charateristics of a semaphore and a
condition variable and SemaMonitor combines all charateristics of a
semaphore and an eventcount , they only use an event object and and a
very fast and very efficient and portable FIFO fair Lock , so they are
fast and they are FIFO fair.
Now you can pass the SemCondvar's initialcount and SemCondvar's
MaximumCount to the construtor, it's like the Semaphore`s InitialCount
and the Semaphore's MaximumCount.

Like this:

t:=TSemaMonitor.create(true,0,4);

When you pass True in the first parameter of the constructor the
signal(s) will not be lost even if there is no waiting threads, if it's
False the signal(s) will be lost if there is no waiting thread.

As you will notice i have used a scalable and efficient and FIFO fair
Lock inside SemaCondVar.pas, i have made , but you will notice that
this Lock is now portable to the x86 systems and to Linux(x86) , Mac
OSX(x86) and Windows(x86), but if you want to port it to other systems
than the x86, please change inside SemaCondVar.pas the TALOCK by the
TCriticalSection of the SyncObjs unit and it will be portable to other
systems than the x86. That's all. So enjoy SemaCondvar and SemaMonitor.


You can download SemaCondVar from:

http://pages.videotron.com/aminer/


Here is the methods that i have implemented :

TSemaCondvar = class
public

constructor
Create(m1:TCriticalSection;state1:boolean=false;InitialCount1:longword=0;MaximumCount1:longword=INFINITE);
destructor Destroy; override;
function wait(mstime:longword=INFINITE):boolean;
procedure signal();overload;
procedure signal_all();
procedure signal(nbr:integer);overload;
function WaitersBlocked:integer;
end;

TSemaMonitor = class
public
constructor
Create(state1:boolean=false;InitialCount1:longword=0;MaximumCount1:longword=INFINITE);
destructor Destroy; override;
function wait(mstime:longword=INFINITE):boolean;
procedure signal();overload;
procedure signal_all();
procedure signal(nbr:integer);overload;
function WaitersBlocked:integer;

end;

Please take a look a the test.pas Object Pascal demo inside the zipfile,
compile and run it...

Language: FPC Pascal v2.2.0+ / Delphi 7+: http://www.freepascal.org/

Operating Systems: Windows, Mac OSX , Linux , Unix...


Required FPC switches: -O3 -Sd -dFPC -dFreePascal

-Sd for delphi mode....
{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems

{$DEFINE CPU64} and {$DEFINE Windows64} for 64 bit systems

{$DEFINE OSX} for Mac OSX on Delphi XE4 to XE5


Thank you,
Amine Moulay Ramdane.
0 new messages