Can the hardware fetch&add instruction guarantee wait-free execution?

49 Views Asked by At

So, if multiple processes execute FAA, is there any guarantee that this FAA instruction will be executed in a wait-free manner? What if processes that finish executing this instruction do not stop there but repeatedly try to execute it?

1

There are 1 best solutions below

0
RmbRT On BEST ANSWER

An algorithm is wait-free if it does not contain retry loops or wait loops. Since fetch_add() never fails (unlike compare_exchange_weak()), the operation itself is suited for writing wait-free algorithms (as no retry loops are needed). Of course, whether an algorithm using the fetch_add() instruction actually is wait-free depends on the rest of the algorithm. As long as fetch_add() is supported as an instruction on your hardware, it is wait-free. Only if it is not supported, and has to be emulated via CAS loops or LL/CS, it is no longer wait-free, as those are not wait-free.