[Question] HW7 Dropping the Hazard Bag
thekioskman opened this issue · 3 comments
From my understanding to drop the hazard bag we use the atomic pointer at the start of the list and perform a CAS operation with the next node. But in order to get access to the next node, we have to dereference the head node. But in between the instructions of our head.load(), deref head to get next pointer and CAS. The head pointer could already be free'd, and then we would be trying to dereference a free'd pointer.
I can't think of any way to get around this. Is there anything I am missing?
As written in the comment, each slot never gets deallocated until the deallocation of HazardBag. So you don't need to worry about that situation.
does that mean we can assume the drop of hazard bag in sequential? Won't multiple threads still call the drop at the same time?
Yes. drop
requires mutable reference to HazardBag, so there should not be multiple shared references.