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