stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 289

Day 289 of 365 · Expert · Month 10: Bits and data

Shared memory

Several chips share one memory: a housing's stack with get and put, write permissions through address ranges and a lock that prevents half-written records.

Lesson 20 min Week 42

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:

AddressesWriterContent
0everybody, only with the locklock
10–19chip Avalues room A
20–29chip Bvalues room B
30–39chip Cvalues 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
Warning

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.

Note

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

The stack with its pointer slot 0 10 slot 1 20 slot 2 30 slot 3 slot 4 sp = 3 next free slot push 40 pop r0 r0 = 30 last in, first out
Each chip only writes into its own range. Whoever writes several values together takes the lock first.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere