kaist-cp/cs431

[Locks] Can we change while loop of MCSParking lock to If statement?

Coll1ns-cult opened this issue · 2 comments

Hi I wonder if we can change the following statement

while unsafe { (*node).locked.load(Acquire) } { thread::park(); }

to this:
if unsafe { (*node).locked.load(Acquire) } { thread::park(); }

Since we can only unpark() this thread with the lock holder thread, while loop is not a necessity I believe. Is this a valid implementation?

Thanks in Advance!

The park call may have spurious wake up. So it's necessary to be in a loop.

Thanks!