gpt4 book ai didi

multithreading - TMREWSync(TMultiReadExclusiveWriteSynchronizer)问题

转载 作者:行者123 更新时间:2023-12-03 13:16:48 27 4
gpt4 key购买 nike

我对TMREWSync有疑问:

  • 是否可以在不解锁的情况下将“读取锁定”升级为“写入锁定”?
  • 不明白如果BeginWrite返回false怎么办?
  • 最佳答案

  • 是,TMREWSync支持锁升级。像这样使用它:BeginRead ... BeginWrite ... EndWrite ... EndRead
  • System.SysUtils状态中的源代码:

  • The function result of BeginWrite indicates whether another thread got the write lock while the current thread was waiting for the write lock. Return value of True means that the write lock was acquired without any intervening modifications by other threads. Return value of False means another thread got the write lock while you were waiting, so the resource protected by the MREWS object should be considered modified. Any samples of the protected resource should be discarded.



    我的建议是编写算法,使其不依赖于此返回值。源代码与我一致:

    In general, it's better to just always reacquire samples of the protected resource after obtaining a write lock. The boolean result of BeginWrite and the RevisionLevel property help cases where reacquiring the samples is computationally expensive or time consuming.

    关于multithreading - TMREWSync(TMultiReadExclusiveWriteSynchronizer)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60463076/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com