Sign in Join

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

Mailing lists / fpc-pascal / 2009-08

TMultiReadExclusiveWriteSynchronizer is wrongly implemented

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

The current TMultiReadExclusiveWriteSynchronizer as implemented in FPC 2.3.1 is wrong. It use Critical Sections in a standard way which means it blocks all other threads while one thread is doing a Read. This is wrong. It is a MULTI read, SINGLE write synchronizer. So it must only block other thread is a Write is in progress. But allow multiple reads while no Write is in progress.

The TMultiReadExclusiveWriteSynchronizer is currently equivalent to the Delphi 7 TSimpleRWSync class, not the Delphi
TMultiReadExclusiveWriteSynchronizer class.

I have a corrected TMultiReadExclusiveWriteSynchronizer implementation (don't worry, not based on Delphi implementation) that I can donate to FPC. I just need confirmation that the current implementation in FPC is incorrect though.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Florian Klaempfl
to Graeme Geldenhuys
Show quoted text 8 lines
Hi, The current TMultiReadExclusiveWriteSynchronizer as implemented in FPC 2.3.1 is wrong. It use Critical Sections in a standard way which means it blocks all other threads while one thread is doing a Read. This is wrong. It is a MULTI read, SINGLE write synchronizer. So it must only block other thread is a Write is in progress. But allow multiple reads while no Write is in progress.

It is on the safe side but it is not optimal.

Show quoted text 10 lines
The TMultiReadExclusiveWriteSynchronizer is currently equivalent to the Delphi 7 TSimpleRWSync class, not the Delphi TMultiReadExclusiveWriteSynchronizer class. I have a corrected TMultiReadExclusiveWriteSynchronizer implementation (don't worry, not based on Delphi implementation) that I can donate to FPC. I just need confirmation that the current implementation in FPC is incorrect though.

If you have a better for unix this will be fine. IIRC it is not easy (if possible after all?) to implement TMultiReadExclusiveWriteSynchronizer for unix systems.

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote
If you have a better for unix this will be fine. IIRC it is not easy (if possible after all?) to implement TMultiReadExclusiveWriteSynchronizer for unix systems.

What's wrong with these routines: pthread_rwlock_init, pthread_rwlock_rdlock/pthread_rwlock_wrlock, pthread_rwlock_unlock, pthread_rwlock_destroy?

Jonas

Florian Klaempfl
to Jonas Maebe
Show quoted text 10 lines
On 28 Aug 2009, at 10:35, Florian Klaempfl wrote: > If you have a better for unix this will be fine. IIRC it is not easy (if > possible after all?) to implement TMultiReadExclusiveWriteSynchronizer > for unix systems. What's wrong with these routines: pthread_rwlock_init, pthread_rwlock_rdlock/pthread_rwlock_wrlock, pthread_rwlock_unlock, pthread_rwlock_destroy?

I simply don't know but I thought there was a reason it could have been also something like kylix compatibility.

Vinzent Höfler
to Graeme Geldenhuys: The current TMultiReadExclusiveWriteSynchronizer as implemented in FPC 2.3.1 is wrong. It…

Graeme Geldenhuys :

I have a corrected TMultiReadExclusiveWriteSynchronizer implementation (don't worry, not based on Delphi implementation) that I can donate to FPC.

I hope it isn't based on the Delphi one. Last time I heard the Delphi implementation suffers from occasional dead locks.

So any such implementation should be reviews very thouroughly. ;)

I just need confirmation that the current implementation in FPC is incorrect though.

It's not incorrect, just inefficient.

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Vinzent Höfler
to Florian Klaempfl: It is on the safe side but it is not optimal. If you have a better for unix this will be…

Florian Klaempfl :

If you have a better for unix this will be fine. IIRC it is not easy (if possible after all?) to implement TMultiReadExclusiveWriteSynchronizer for unix systems.

It's possible, yes. If it's possible in an efficient way, is another question.

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Marco van de Voort
to Florian Klaempfl: It is on the safe side but it is not optimal. If you have a better for unix this will be…

In our previous episode, Florian Klaempfl said:

Show quoted text 7 lines
> (don't worry, not based on Delphi implementation) that I can donate to > FPC. I just need confirmation that the current implementation in FPC is > incorrect though. If you have a better for unix this will be fine. IIRC it is not easy (if possible after all?) to implement TMultiReadExclusiveWriteSynchronizer for unix systems.

Afaik there is a document on the net about an implementation on Solaris.

Graeme Geldenhuys
to Vinzent Höfler: Graeme Geldenhuys : I hope it isn't based on the Delphi one. Last time I heard the Delphi…
Vinzent Höfler wrote 8 lines
Graeme Geldenhuys : > I have a corrected TMultiReadExclusiveWriteSynchronizer > implementation (don't worry, not based on Delphi implementation) > that I can donate to FPC. I hope it isn't based on the Delphi one. Last time I heard the Delphi implementation suffers from occasional dead locks.

If you read my mail (as quoted above), I clearly stated that it is NOT based on the Delphi one. After all, I brought to attention the Delphi similarities in the FPC code a while back - so I would not introduce copyright code into FPC.

> I just need confirmation that the current implementation in FPC is > incorrect though. It's not incorrect, just inefficient.

I have to disagree. The currently class name is
TMultiReadExclusiveWriteSynchronizer. The currently implementation does NOT allow multi-read (so the class name totally misleading). It uses a simple Critical Section to block any other threads while reading or writing.

At least, the FPC team needs to rename the class to TSimpleRWSync (to be Delphi compatible with the same functionality).

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 9 lines
>> I just need confirmation that the current implementation in FPC is >> incorrect though. > > It's not incorrect, just inefficient. I have to disagree. The currently class name is TMultiReadExclusiveWriteSynchronizer. The currently implementation does NOT allow multi-read (so the class name totally misleading). It uses a simple Critical Section to block any other threads while reading or writing.

This is already known since the beginning. It is just an initial implementation to ease porting.

At least, the FPC team needs to rename the class to TSimpleRWSync (to be Delphi compatible with the same functionality).

Sure. I didn't know TSimple*, otherwise i'd suggest to simply delete it, it was always meant as a placeholder.

But only when there is a validated, portable substitute. Since though limited and inefficient, the current implementation keeps codebases running.