[Question] [HW4] How to store self in target's last in `start_enqueue`?
Closed this issue · 2 comments
m-spitfire commented
The functions swap
and compare_exchange
on AtomicPtr
wants a *mut T
. However, in order to enqueue self
to target
, I need &mut self
not &self
. How can I swap an AtomicPtr
with a value that I have only immutable reference to?
The reference MCS Lock implementation uses an owned value to enqueue:
Lines 43 to 44 in 0bb9805
Lee-Janggun commented
The return type of 'Node::new()' is '* mut Node'. If you have a '&self', just do 'self as * const T as * mut T'
m-spitfire commented
Yep! Didn't know cast like that is valid. Thanks!