kaist-cp/cs431

[Question] Compare exchange of empty segment HW 6 (HashSet)

Closed this issue · 3 comments

I have been having trouble doing a compare and exchange of the segments. What is the expected value of an empty entry in the array? Normally it would be a null pointer, but I have trouble getting this code to work:

unsafe{
((*(new_root.as_raw())).children[0]).compare_exchange( null_thing , new_thing, Ordering::SeqCst, Ordering::SeqCst, guard);
}                       }

in the declaration of the default segment, null pointers are not used, it is just mem: zeroed. So I am not sure how to compare to the empty array entry,

Note that actual values of null pointers are 0. So even if a segment is initialized with mem::zeroed, you can just compare with usual null pointers in Rust.

That makes sense, but I'm sure I keep getting an error when I try to compare with ptr::null().

note:   expected struct `Shared<'_, Segment<T>>`
            found raw pointer `*const _`

As the compiler suggests, you should not compare with ptr::null() since it has an incorrect type. Please look at the documentation of crossbeam's Shared (https://docs.rs/crossbeam/latest/crossbeam/epoch/struct.Shared.html). You can find the correct one there.