I've got a project which has several tasks running and an overall system state I want to track (things like standby mode, whether a toggle state is in one mode or another). Normally, I would have a structure somewhere and use get and set methods to read and write to the state. With multiple tasks, it's not so simple. It seems like in MQX, there's a few ways to tackle this.
The one that immediately comes to mind is that I could send messages to get and set the state, but that becomes either a lot of messages, or passing a large state structure as a message. This is especially cumbersome if I have one task managing the state. It seems like I would have to send a message to make a change, the when another task wants to read a state, it has to send a message requesting it, then wait for the state to get shipped back. Seems like a lot of overhead. Is there something a little simpler? Perhaps sending a message when the state changes, some task updating the state somewhere, then the state is visible to all other tasks through some shared memory or a simple get_state() function call. Any thoughts or ideas here would be appreciated.
The overall concept is a task that is in charge of managing the state (so only one task can write) but anyone can read it. Seems this should be a fairly common problem, and I'm sure there's some sort of design pattern that fits this with little overhead in MQX.