Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Can i use Peterson Lock as SMP lock??

rkmanikanta
Beginner
554 Views
Hi,
Can i use Peterson Lock as SMP Lock, if the processor doesn't support Get-and-Set instruction?
Thanks,
Mani
0 Kudos
4 Replies
Dmitry_Vyukov
Valued Contributor I
554 Views
Yes, of course. However, then hardware has to support either sequentially-consistent memory model or #StoreLoad style memory fences.
0 Kudos
anthony_williams
Beginner
554 Views
Peterson's lock was designed for precisely this scenario. However, you need to ensure that the operations become visible to the other processors in the right order. The algorithm assumes a sequentially-consistent memory model, and on some platforms this will require memory fence operations before and/or after some of the stores and loads.

You also need to bear in mind that Peterson's lock is not a replacement for a general-purpose mutex --- each thread that tries to access the critical section must have a specific ID. The basic algorithm only works with 2 specific threads, though it is possible to extend it to more.
0 Kudos
rkmanikanta
Beginner
554 Views
Hi,
thanks for the reply.
But how can we extend Peterson lock for N-processes?
Thanks,
Mani
0 Kudos
Chris_M__Thomasson
New Contributor I
554 Views
0 Kudos
Reply