Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-02

TMultiReadExclusiveWriteSynchronizer does not allow "read lock" promoting to a "write lock"

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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.

<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>
Inoussa O.

Reply by email

Nikolai Zhubr
to Inoussa OUEDRAOGO

19.02.2010 23:02, Inoussa OUEDRAOGO:

Show quoted text 10 lines
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

Show quoted text 26 lines
<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>

Reply by email

Inoussa OUEDRAOGO
to Nikolai Zhubr

2010/2/19 Nikolai Zhubr :

Show quoted text 17 lines
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?

The case here is to note that the FPC 2.4.0 (and trunck) implementation does not allows lock upgrading while Delphi, FPC 2.2.x does. This will free people
some debugging time , I talking from experience. The sample is just a test case to show the problem.

Inoussa O.

Reply by email