Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Delphi-News aus aller Welt (https://www.delphipraxis.net/58-delphi-news-aus-aller-welt/)
-   -   Readers-writer lock - Part 4: Improving TLightweightMREW (https://www.delphipraxis.net/206944-readers-writer-lock-part-4-improving-tlightweightmrew.html)

DP News-Robot 10. Feb 2021 23:00

Readers-writer lock - Part 4: Improving TLightweightMREW
 
While the TLightweightMREW*is quite handy, it is not perfect. There's a weird assymmetry in it. On all operating systems that Delphi can compile for, read*locks are reentrant (recursive) while write*locks are not. In other words, if a thread already owns a read lock, it can call BeginRead*again and it will succeed. Write locks are different. If a thread already owns a write lock and calls BeginWrite*again, it will either deadlock (on Windows) or raise an exception (on other supported platforms).

This is, however, relatively simple to fix. I have implemented a simple wrapper for the TLightweightMREW lock in TLightweightMREWEx. This new record uses internal TLightweightMREW*to provide locking and adds some simple logic to implement write lock reentrancy. The implementation and accompanying test program rwReentrantWriter*can be found at*https://github.com/gabr42/examples/t...-writer%20lock.

Read more »[SIZE=-2]--- Published under the Creative Commons Attribution 3.0 license[/SIZE]


Weiterlesen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:43 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz