简体   繁体   中英

Is it okay to read either old version or new version in RCU lock?

I have a question about RCU lock.

As far as I know, RCU allows some readers (which started before grace period and ends in grace period) to have either old version or new version.

Look up the attached image.

在此输入图像描述

So Readers that starts before yellow part and ends within yellow part can read either updated (removed) value or old value.

However, my question is why is it okay for a reader to have indeterminate value? I think all readers should have determinate value, which means it should not be either old value or new value.

Am I missing something?

Thanks.

That is how RCU works and that is the main difference between RCU and locks.

Using, for example, RW locks you can be sure that during the update every reader stops and waits for the update to complete. Then all readers see the updated data at once.

RCU by design allows you to see either data before the update or after, but for many use cases it is OK. The main advantage of RCU is that readers never get blocked and a writer never get blocked.

Sure, if the logic of you program require strict data coherency among the working threads -- RCU is not the best choice. Have a look at RW Locks then...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM