Search code examples
algorithmmemoryconcurrencylock-free

What does fetch_and_store operation does


I have an algorithm with a fetch_and_store operation inside it. I globally understand the algorithm except this line : pred : ^qnode := I->prev := fetch_and_store (L, I). This is the CLH algorithm (for concurrency programming). Can someone help me understanding this part.

The algorithm : http://www.cs.rochester.edu/research/synchronization/pseudocode/ss.html#clh


Solution

  • fetch_and_store (L, I) atomically writes I to L and returns previous value of L. This ensures that lock node will be worked with only with one thread: the thread takes it for processing and replaces with other node. Other thread will take the node we've placed here.