L10 & L11 Flashcards

1
Q

Explain how a binary sempahore works.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does tas affect the shared variable in a binary semaphore?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does tas achieve atomicity for critical code?

A

Test-and-set locks access to memory from other processors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does tas waste bus cycles?

A

If S is busy and is wanted by another thread, the semaphore will wait continuously in a loop until S is free.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List examples of synchronisation primitives. What do they have in common?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can atomicity be achieved without holding the bus until completion?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When is the load linked flag cleared?

A

when another core writes to the locked address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly