ABA + Memory Reclamation Flashcards
What is the ABA problem?
Thread 1 reads a value. thread 2 interrupts and changes it. thread 1 writes original value back again (nodes are recycled)
ABA problem in the book.
Head ends up pointing to a node that is
not in the queue anymore, but has been
added to the free-list
Solution to ABA
Each pointer should have a counter. it is unique over the lifetime of the node.
What class should we use for the pointer
AtomicStampedReference class
What happens to nodes if we dequeue them
we depend on built-in garbage collection to remove them from memory
Solution to no garbage collector:
each thread has own private free-list of unused queue entries
how does enqueue and dequeue work for the free-lists
enq = get node from free list
deq = add removed node to free-list
What should we do if the free-list is empty
allocate new node through dynamic memory
Problem with free list?
when nodes are recycled = ABA problem