Hi. I'm developing a generic - configurable communication DLL which I will use in my future applications. To obtain a great flexibility I used three threads, one thread for each level of my protocol. The data exchange is done with thread safe queues.
During debug phase I found a strange problem: sometimes a thread didn't receive any data from the queue and timed out. You can imagine this flow:
1. Thread A writes a packet to 'QueueAtoB'
2. Thread A waits (polling) data from 'QueueBtoA': while ((!ItemsInQueue) && (!TimeOut));
In the meantime thread B is always polling for data in 'QueueAtoB'.
I saw that, after Thread A writes data to Queue, Thread B doesn't work. It seems Thread A obtain a bigger priority and Thread B doesn't live for some seconds...
I solved this problem putting a ProcessSystemEvent() inside the polling of point 2 above: while ((!ItemsInQueue) && (!TimeOut)) ProcessSystemEvent();
My question: Is this correct ??
Thank you very much.