I'm having trouble over deciding a final implementation for a fairly simplistic Modbus application. Essentially, multiple static serial port wrappers are accessed by multiple different threads.
At the moment I employ the Facade pattern and abstract much of the detail of these static classes. This facade class also synchronizes any operations that require interfacing with multiple devices simultaneously.
Having come across this previous asked question: Message queue vs thread lock
Currently, I simply surround the singleton instance getter on each static serial port with a lock()
to add SOME thread safety. As of yet, I haven't encountered any issues with this implementation and it is fairly scalable from my understanding (as Modbus is a multidrop protocol).
However, I'm wondering whether a BlockingCollection<>
with callbacks may be a better choice as there is a clearer separation of concerns. The problem I am having is with implementation.
Synchronizing on multiple devices requires that most operations get performed synchronously and due to this requirement - is a message queue with callbacks the best option?
I also have concerns that implementing such a queue is just adding unnecessary overhead as a majority of calls are granular and having to define callback methods for each is just going to bloat callers.
Apologies if I haven't expressed my question clearly enough, if further clarification is needed will be happy to provide - struggling for a few days on this concern.
Aucun commentaire:
Enregistrer un commentaire