Using only equal priority tasks (best practice?)

Hello everyone!

I have a project developing a “data gateway” , basically data coming from different sources (CAN, UART or BLE) and the data is transformed accordingly (from different protocols to other protocols) and sent to the desired destination (again CAN, UART or BLE).

The data flows in an “event” like manner, for example if a CAN message received, it notifies the desired protocol “decoder” which transforms the data accordingly to the other protocol, and the protocol “encoder” notifies the other desired data channel for example BLE.

There are 6 tasks currently (maybe adding 1 more for fw update) and I am using the same priority on every one of them, since there is no “main” data channel. The system is working really fine, with high data throughput, and the tasks never block each other it seems.

I am just curious if it is a good practice to use a lot of equal priority tasks? Usually on other projects I always could determine a clear hierarchy between processes, but for this project it seems for me this is the way to go.

Good question! :grin:

Standard answer: It depends. An architecture models the problem the system is supposed to solve. If equal priority tasks model the problem sufficiently and help towards a good working solution, it is good practice.

That is all there is to it.

1 Like

Priority only matters if you have multiple tasks wanting to run at a time.

In your case, if some channels can deliver data at a significantly faster rate than others, it might make sense to give them a higher priority so that data can be processed before too much more data comes in.

To repeat, if you can process all the data swiftly as it comes in so you don’t start to backlog the faster channels, then priority doesn’t really come into play. If you might hit momentary saturation points, then priority might allow you to reduce the chance of lost data, or minimize buffer requirements.

1 Like