Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1696 Discussions

SemaMonitor and SemaCondvar were updated to version 1.4

aminer10
Novice
292 Views

Hello,

My inventions that are my SemaMonitor and SemaCondvar were updated to version 1.4, i have added an iterator on the FIFO Queue to make WaitersBlocked()(that's the number of blocked threads on the SemaMonitor or the SemaCondvar) works correctly, and you can wait indefinitly or for a  time-out interval in milliseconds.

You have to know that my SemaMonitor and SemaCondvar synchronization objects combines all the characteristics of a Semaphore and also an EventCount and also a windows Manual-reset event and also a windows Auto-reset event and they are portable to Windows,Linux and OSX on x86 architecture.

You can download my SemaMonitor and SemaCondvar from:

https://sites.google.com/site/aminer68/semacondvar-semamonitor

You will find both of the SemaMonitor and SemaCondvar classes inside
the file called SemaCondvar.pas


Author: Amine Moulay Ramdane.

Description:

SemaCondvar and SemaMonitor are new and portable synchronization objects , SemaCondvar combines all the characteristics of a semaphore and a condition variable and also a windows Manual-reset event and also windows Auto-reset event, and SemaMonitor combines all charateristics of a semaphore and an eventcount and also a windows Manual-reset event and also windows Auto-reset event, 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 and and they are portable to Windows,Linux and OSX on x86 architecture.

I feel that i must explain to you how do work my inventions that are my SemaCondvar and SemaMonitor objects, you will find those classes inside the SemaCondvar.pas file inside the zip file, 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 a very fast and efficient and portable FIFO fair Lock , so they are fast and they are FIFO fair.

When you set the first parameter of the construction to true it will add the characteristic of a Semaphore to the condition variable or to the Eventcount, so the signal will not be lost if the threads are not waiting for the SemaCondvar or SemaMonitor objects, but when you set the forst parameter of the construtor to false it will not behave like a Semaphore because if the threads are not waiting for the SemaCondvar or SemaMonitor the signal will be lost..

Now you can pass the SemaCondvar's or Semamonitor's initialcount and SemaCondvar's or SemaMonitor's MaximumCount to the construtor, it's like the windows Semaphore`s InitialCount and the Semaphore's MaximumCount.

Like this:

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

You have 5 options in the defines.inc file for setting the kind of locks, just look inside defines.inc , if you want to set it for the Mutex that is energy efficient because it blocks the threads, uncomment the option Mutex, if you want to set it for my node based scalable Lock, uncomment the option MLock, if you want to set it for my scalable array based lock called AMLock just uncomment the option AMLock inside defines.inc, if you want to set it for Ticket Spinlock just uncomment the option TicketSpinlock ,If you want to set it for Spinlock just uncomment the option Spinlock.

Here is the methods that i have implemented :

TSemaCondvar = class
public

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

TSemaMonitor = class
public
constructor
Create(state1:boolean=false;InitialCount1:long=0;MaximumCount1:long=INFINITE);
destructor Destroy; override;
function wait(mstime:longword=INFINITE):boolean;
procedure signal();overload;
procedure signal_all();
procedure signal(nbr:long);overload;
function WaitersBlocked:integer;
procedure setSignal;
procedure resetSignal;
end;
Language: FPC Pascal v2.2.0+ / Delphi 7+: http://www.freepascal.org/

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

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

-Sd for delphi mode....

Required Delphi switches: -DMSWINDOWS -$H+ -DDelphi

For Delphi XE-XE7 use the -DXE switch

{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems

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


Thank you,
Amine Moulay Ramdane.

0 Kudos
0 Replies
Reply