-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Single producer, multi-consumer model. Everything in parallel. Nice because no thread will move faster than the producer and no thread is slowed down by another thread because they are all independent of each other.
Responsible for polling flight instrumentation sensors, moving those values into memory locations shared between itself and the consumers (one memloc per consumer), and notifying each consumer that new data is available.
sensor_data = get_data()
for c in consumers:
if( c.shared_mem.is_avail() ):
c.lock_shared_mem()
c.update_shared_mem(sensor_data)
c.unlock_shared_mem()
c.notify()
The notification mechanism is a binary semaphore signifying that data is "fresh" or "stale". The producer will overwrite fresh data.
Reads data from shared memory and then operates on it. Controls consumer crunches the meco algorithm. Logging consumer writes to a file, Comms consumer does communication stuff.
while True:
if( notified() ):
lock_shared_mem()
local_data = shared_mem; //copy data
unlock_shared_mem()
//comms() or controls() or log()
State Machine
If a consumer is slow enough, the producer will update the shared memory with fresh data multiple times before the consumer can read. This means dropped data, but it is also means that we will never run a consumer on stale data.