Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #2074 > unrolled thread
| Started by | aminer <aminer@toto.net> |
|---|---|
| First post | 2014-01-29 18:50 -0800 |
| Last post | 2014-01-29 18:50 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.programming.threads
I eaplain my new LW_RWLockX algorithm aminer <aminer@toto.net> - 2014-01-29 18:50 -0800
| From | aminer <aminer@toto.net> |
|---|---|
| Date | 2014-01-29 18:50 -0800 |
| Subject | I eaplain my new LW_RWLockX algorithm |
| Message-ID | <lcc41l$hug$2@news.albasani.net> |
Hello,
I will explain my new LW_RWLockX algorithm...
you have to undertand first my LW_RWLock algorithm that is
not starvation-free..
Here it's:
http://pages.videotron.com/aminer/rwlock1.html
Here is what i have changed, first i have to not
use spin-wait cause if you loop back it will not be starvation-free and
so you can still have starvation , so i have got rid of looping back and
i have done this:
In the TRWLOCK.RLock() method you will read this:
procedure TRWLOCK.RLock(var myid:integer);
begin
myid:=GetCurrentProcessorNumber;
if (FCount3^.fcount3 = 1)
then
begin
LockedExchangeAdd(nbr2,1);
while nbr3=0 do sleep(0);
LockedExchangeAdd(nbr2,-1);
end;
LockedExchangeAdd(FCount1^[myid].fcount1,1);
if (FCount3^.fcount3 = 0)
then
else
begin
LockedExchangeAdd(nbr,1);
LockedExchangeAdd(FCount1^[myid].fcount1,-1);
while nbr1=0 do sleep(0);
LockedExchangeAdd(FCount1^[myid].fcount1,1);;
LockedExchangeAdd(nbr,-1);
end;
end;
and in the TRWLOCK.WLock() method you will read this:
procedure TRWLOCK.WLock;
var i:integer;
begin
lock.enter;
FCount3^.fcount3:=1;
repeat;
nbr1:=1;
asm pause end;
nbr1:=0;
until nbr=0;
FCount3^.fcount3:=0;
repeat;
nbr3:=1;
asm pause end;
nbr3:=0;
until nbr2=0;
FCount3^.fcount3:=1;
for i:=0 to GetSystemThreadCount-1 do
begin
while (FCount1^[i].fcount1<>0)
do
begin
//if mysleep=0 then sleep(0)
//else sleep(1);
end;
end;
end;
--
Notice in TRWLOCK.WLock() that i have first to
set FCount3^.fcount3 to 1 to block the reader threads
and i have done also this in the reader side:
repeat;
nbr1:=1;
asm pause end;
nbr1:=0;
until nbr=0;
this repeat until loop will just unblock the reader threads that entered
between the following two LockedExchangeAdd() in the reader side:
LockedExchangeAdd(nbr,1);
LockedExchangeAdd(nbr,1);
after that i am setting FCount3^.fcount3 to 0 to unblock the new reader
that are coming and after that i am using the following repeat loop
repeat;
nbr3:=1;
asm pause end;
nbr3:=0;
until nbr2=0;
this repeat until loop will just unblock the reader threads that entered
between the following two LockedExchangeAdd() in the reader side:
LockedExchangeAdd(nbr2,1);
LockedExchangeAdd(nbr2,-1);
this way i the reader threads will not starve forever the writers,
and this way the algorithm will be starvation-free and it is
fast and scalable, i have just tested it and it's scalable.
You can download all the variants of my scalable RWLock 2.15 from:
http://pages.videotron.com/aminer/
And please take a look at my new algorithm inside LW_RWLockX.pas
algorithm inside the zip file.
Thank you,
Amine Moulay Ramdane.
Thank you,
Amine Moulay Ramdane
Back to top | Article view | comp.programming.threads
csiph-web