Scalable RWLocks that work across processes and threads

Scalable RWLocks that works across processes and threads version 5.0

Author: Amine Moulay Ramdane.

Description:

Those are my inventions of a fast, and scalable and starvation-free and fair and lightweight Multiple-Readers-Exclusive-Writer Lock that spin-wait called LW_RWLockX, it works across processes and threads, and of a fast, and scalable and starvation-free and fair and Multiple-Readers-Exclusive-Writer Lock that doesn't spin-wait called RWLockX, it works across processes and threads.

The parameters of the constructor of LW_RWLockX are: first parameter is the name of the scalable RWLock to be used across processes, if the name is empty, it will only be used across threads. The second parameter is the size of the array of the readers, so if the size of the array is equal to the number of parallel readers, so it will be scalable, but if the number of readers are greater than the size of the array , you will start to have contention. The third parameter is the size of the array of my scalable Lock that is FIFO fair that is called AMLock, the number of threads can go beyond the size of the array of the scalable AMLock, please look at the source code of my scalable algorithms to understand.

The parameters of the constructor of RWLockX are: first parameter is the name of the scalable RWLock to be used across processes, if the name is empty, it will only be used across threads. The second parameter is the size of the array of the readers, so if the size of the array is equal to the number of parallel readers, so it will be scalable, but if the number of readers are greater than the size of the array , you will start to have contention. Please look at the source code of my scalable algorithms to understand.

Here is how to use my new inventions that are my scalable LW_RWLockX and RWLockX across processes:

Just create a scalable rwlock object by giving a name in one process by calling the constructor like this:

scalable_rwlock.create('amine');

And you can use the scalable rwlock object from another process by calling the constructor by using the name like this:

scalable_rwlock.create('amine');

So as you are noticing i have abstracted it efficiently..

I have also used my following implementation of FNV1a hash function to make my new variants of RWLocks scalable (since FNV1a is a hash algorithm that has good dispersion):

function FNV1aHash(key:int64): UInt64;

var

i: Integer;

key1:uint64;

const

FNV_offset_basis: UInt64 = 14695981039346656037;

FNV_prime: UInt64 = 1099511628211;

begin

//FNV-1a hash

Result := FNV_offset_basis;

for i := 1 to 8 do

begin

key1:=(key shr ((i-1)*8)) and $00000000000000ff;

Result := (Result xor key1) * FNV_prime;

end;

end;


You can go to download the zip files by clicking on the following web link:

https://drive.google.com/drive/folders/1togENNVCioYZDWFiH2YDHVMBzX2YzBho?usp=sharing

- Platform: Windows, Unix and Linux on x86

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

Required FPC switches: -O3 -Sd

-Sd for delphi mode....

Required Delphi switches: -$H+ -DDelphi

For Delphi XE-XE7 and Delphi tokyo use the -DXE switch

You can configure it as follows from inside defines.inc file:

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

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