Question

I have C# multi threading program that using UART trough c++ COM object. I'm accessing UART from couple threads and it is not aloud. Mu solutions:

  1. access to UART only from one thread and perform all other threads requests in the beginning of each cycle. The problem with this solution is that all other threads will wait a lot of time before receiving response.
  2. Create prioritized thread that only he will access UART. The problem with this solution is that it is very risky. What solution is the best and why? There is another solution?
Était-ce utile?

La solution

I would suggest a dedicated thread that pulls requests from a ConcurrentQueue and operates on the UART. All other threads should Enqueue requests and continue on with their work, so there's no waiting involved. Does that fit your needs?

Here's the documentation for ConcurrentQueue

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top