Previous | Next --- Slide 24 of 37
Back to Lecture Thumbnails
Cake

Is the purpose of reclaim here purely to ensure that we don't use astronomical amounts of memory?

jkorn

Right, and to avoid memory leaks. I suppose you could free everything at the end when you are done using the data structure, but I think the idea is that this is something that will be used for a while (i.e. a work queue), so that's probably not the best solution.

paramecinm

Reclaim is to make sure that the allocation and deletion are performed by the same thread.

aperiwal

Here, pop just moves the head to the next element in the queue without deleting it. The delete is done later by push(using the reclaim pointer). Thus, only one thread handles the insertion and deletion of the ndoes.

pdp

Is the allocation and deletion done by the same thread because of new and delete not being thread safe? Because, pop has a head!=tail condition which will prevent that thread deleting the location accessed by the push thread anyways.

kayvonf

To everyone: The purpose of this design is to make sure the same thread is allocating and deleting memory used by the queue -- allowing for a non-thread safe allocator to be used. This can be important, since a thread safe allocator might be implemented using locks, and the point of this queue's design was the avoid locks.