6

What is the difference between the test and set implementation of mutex and the Peterson's Algorithm?

Which of them is actually used in the real systems?

1
  • As for the "which of them is actually used" part of your question it would be nice self-answer if you'd find out from some systems with open source code like: FreeRTOS, Linux, ReactOS and link the source code...
    – xmojmr
    Commented Sep 28, 2014 at 6:16

1 Answer 1

2

Peterson's algorithm doesn't work very well in a modern memory architecture with caching. You end up needing to flush constantly. Test-and-set and interlocked operations like interlocked exchange or interlocked increment are going to be much more commonly used and have direct support on the CPU.

2
  • Can you please explain the meaning of "needing to flush constantly" Commented Sep 27, 2014 at 19:10
  • 1
    I mean flushing the L1 cache so that the other CPUs can see the values of the flags. See en.m.wikipedia.org/wiki/CPU_cache Commented Sep 27, 2014 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.