L10 & L11 Flashcards
Explain how a binary sempahore works.
Binary semaphore: a single shared variable whose value is used to protect a shared resource
If the variable is 1, the resource is free. If the variable is 0, the resource is not free.
Operations: wait(var) takes the lock, signal(var) releases the lock
How does tas affect the shared variable in a binary semaphore?
The variable is now the logical inverse of the standard definition.
If the variable is 0, the resource is free. If the variable is 1, the resource is not free.
How does tas achieve atomicity for critical code?
Test-and-set locks access to memory from other processors.
How does tas waste bus cycles?
If S is busy and is wanted by another thread, the semaphore will wait continuously in a loop until S is free.
List examples of synchronisation primitives. What do they have in common?
- Test-and-set instruction
- Fetch-and-add (returns the value of a memory location and increments it)
- Compare-and-swap
They are read-modify-write instructions that lock the snoopy bus during their execution
How can atomicity be achieved without holding the bus until completion?
Load-linked: core keeps some state for the load (load linked flag and saves the address)
Store-conditional: only succeeds if load linked linked flag set
When is the load linked flag cleared?
when another core writes to the locked address