[fpc-devel] TMultiReadExclusiveWriteSynchronizer does not allow "read lock" promoting to a "write lock"
Nikolai Zhubr
n-a-zhubr at yandex.ru
Fri Feb 19 22:15:56 CET 2010
19.02.2010 23:02, Inoussa OUEDRAOGO:
> Hi
>
> The TMultiReadExclusiveWriteSynchronizer implementation does not allow
> "read lock" promoting
> to a "write lock". The program above hang in FPC 2.4 and 2.5.x while
> working in Delphi and
> FPC 2.2.x. It hangs at the "x.Beginwrite();" instruction. The
> implementation clearly does
> not support this scenario. It will be helpfull to note this in the
> documentation.
AFAIK entering exclusive lock without releasing multiple-read lock is
very unsafe regarding deadlocks (Almost deadlock-guaranteed). Of course
it is safe in the example, but why bother about special 1-thread
scenario if multithreaded code will be unsafe anyway?
Nikolai
>
> <code>
> program test;
>
> {$mode objfpc}{$H+}
>
> uses
> SysUtils;
>
> var
> x : TMultiReadExclusiveWriteSynchronizer;
> begin
> x := TMultiReadExclusiveWriteSynchronizer.Create();
> x.Beginread();
> WriteLn('Beginread');
> x.Beginwrite();
> WriteLn('Beginwrite');
> x.Endwrite();
> WriteLn('Endwrite');
> x.Endread();
> WriteLn('Endread');
>
> ReadLn;
> end.
> </code>
>
More information about the fpc-devel
mailing list