2 ms·
Right - if the pattern in the referenced blog post is used to implement lazy init, racing threads can double initialize. But it's not possible to upgrade a rea
by reitzensteinm 2y ago
Right - if the pattern in the referenced blog post is used to implement lazy init, racing threads can double initialize.
But it's not possible to upgrade a read to write lock as racing threads can cause a deadlock, and upgradable RwLock variants don't hand out multiple upgradable read locks.
To maintain concurrent access, the referenced code must recheck the data once a write lock is granted, to gracefully handle TOCTOU.
(I know you were making a general point, I'm just fleshing out this specific example)