Reading Comprehension - Subtle memory ordering rules

shaharhada

Honorable
Jul 27, 2020
321
8
10,685
In the source:
https://en.wikipedia.org/wiki/Spinlock
I have question about the sentence:
On later implementations of the x86 architecture, spin_unlock can safely use an unlocked MOV instead of the slower locker XCHG. This is due to subtle memory ordering rules which support this, even though MOV is not a full memory barrier.
What is sutble memory ordering rules?
Why MOV is not a full memory barrier and what is instruction(s) that has a full memory barrier?
And what the meaning of the sentence? And how it can express in other simple words?
Thanks for answering...
 
You already appear to understand "memory ordering tools", etc..

Focus on the word "subtle".

Reference:

https://dictionary.cambridge.org/us/dictionary/english/subtle

Small little changes to the memory ordering rules that most people (including myself) would not notice and/or know how to apply such small little changes.

Changes that allow more flexibility and application of MOV but are likely not obvious in appearance nor application.
 
  • Like
Reactions: shaharhada
You already appear to understand "memory ordering tools", etc..

Focus on the word "subtle".

Reference:

https://dictionary.cambridge.org/us/dictionary/english/subtle

Small little changes to the memory ordering rules that most people (including myself) would not notice and/or know how to apply such small little changes.

Changes that allow more flexibility and application of MOV but are likely not obvious in appearance nor application.
What is to "acquire a lock" meaning?
 
When a spinlock is active, it has acquired (gained) a lock. Meaning other code can't utilize that thread.
I think that I understand you, but I am not exactly.
What the meaning of the sentence "when a spinlock is active, it has acquired a lock."
It is a kind of procedure?
The meaning is that Everything I need a lock, I use spinlock and create a one ? i.e. acquired a lock???
 
I think that I understand you, but I am not exactly.
What the meaning of the sentence "when a spinlock is active, it has acquired a lock."
It is a kind of procedure?
The meaning is that Everything I need a lock, I use spinlock and create a one ? i.e. acquired a lock???
First, spinlocks are for multi-threaded software. They are used to synchronize threads when they are accessing a shared resource. That could be memory or I/O.
So if you are using only memory that is exclusively mapped into your thread then you don't need a lock. If you are trying to exchange information into shared memory, then you need a spinlock when you are reading or writing that memory.
The examples shown in Wikipedia, in assembly language would never be encountered in real life programming, unless you were debugging a compiler or OS. You would use higher level language constructs. Maybe this would help -- https://www.justsoftwaresolutions.co.uk/threading/locks-mutexes-semaphores.html