Search code examples
delphifiremonkey

TMultiReadExclusiveWriteSynchronizer for android/ios


On all platforms (except windows) TMultiReadExclusiveWriteSynchronizer is a TSimpleRWSync that internally simply use Tmonitor.enter / Tmonitor.exit and this is quite bad because only one read access at a time. Is their any equivalent of TMultiReadExclusiveWriteSynchronizer (windows version) that work on Android/iOS ?


Solution

  • There is TLightweightMREW record in System.SyncObjs fully implemented on all platforms as thin wrapper around native OS implementations. Introduced in 10.4.1 Sydney.

    There are some things to keep in mind:

    • Read access can be called recursively from same thread, but write access cannot - it will deadlock on Windows and raise exception on Posix platforms
    • Read access cannot be upgraded to write access.