What you learn today
- Several chips, one memory
- Write permissions
- Locks
Three chips measure in three rooms, a fourth shows everything on a board. Instead of every measuring chip writing to the board itself, they all put their values into a shared memory. The board chip only reads there. That is clean – as long as nobody gets in anyone else's way.
Several chips, one memory
Every IC housing has a stack with 512 slots. Other chips reach it with get and put if they know its ReferenceId:
lbn id HOUSING HASH("Speicher") ReferenceId Average
put id 10 value # write address 10
get value id 20 # read address 20
An empty housing without a task of its own is such a big, shared memory. For single values a logic memory (StructureLogicMemory) with its Setting is enough too.
Write permissions
The most important rule: every slot has exactly one writer. Fix the addresses and write them into every chip involved:
| Addresses | Writer | Content |
|---|---|---|
| 0 | everybody, only with the lock | lock |
| 10–19 | chip A | values room A |
| 20–29 | chip B | values room B |
| 30–39 | chip C | values room C |
If two chips write to the same slot, whoever came last wins – and nobody notices.
Locks
If several values belong together, say temperature and pressure of the same reading, nobody may read in between. A lock takes care of that: whoever wants to write enters its ReferenceId, checks in the next tick whether it is still there, writes and releases with 0.
Why check only in the next tick? If two chips see a free lock in the same tick, both enter themselves. Only one is in there afterwards – the other one sees a foreign number when checking and waits.
lbn lock MEMORY HASH("Sperre") Setting Average
beq lock me write # the lock is ours
bnez lock start # foreign: wait
sbn MEMORY HASH("Sperre") Setting me
j start # check next tick
A lock that is never released paralyses everybody else. Always release it in the same section in which you write, and write nothing in between that could raise an error.
In the exercise the lock and the values are logic memories so the test can watch them. In the game the same pattern works with get and put on a housing.
Diagram
Exercise
Task
Your chip writes temperature and pressure of the sensor “Raum” into the memories “TempA” and “DruckA” – but only with the lock in the memory “Sperre”:
- lock 0: enter your own
ReferenceId, check in the next tick - lock is your own: write both values, then set the lock to 0
- lock foreign: write nothing, light “Warten” on
- if the memory “Sperre” is missing, nothing is written
Hints
Hint 1
Your own number is already in me (l me db ReferenceId).
Hint 2
Order: bnan, beq lock me write, set the light, bnez lock start, take the lock.
Hint 3
In the section write: two values, then sbn … Sperre … Setting 0.
Quiz
3 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in