Question

I have an algorithm (task in VxWorks) that is reading data from multiple queues to be able to manage priorities accordingly. Now , the msgQReceive( ) function, can be set to WAIT_FOREVER which would make it a blocking call until something is available to receive and process. Now how can I do this if I have multiple queues? Currently I check in a while(1) loop if any of the queues have any contents and receive them if so but if nothing is there, my algorithm just spins and spins and spins and eats CPU resources for nothing. How can I prevent this best?

Was it helpful?

Solution

You should be able to use VxWorks events coupled with a Message Queue. See msgQEvStart function and Kernel Programmer's Guide, section 7.9.

This is akin to using a select() for I/O operation. You do a blocking eventReceive which returns a bitmask indicating which queue has content and you then do a non-blocking msgQReceive to retrieve the data.

Or you can look at How can a task wait on multiple vxworks Queues? which I wrote a while ago,

OTHER TIPS

As already mentioned, you could use events, alternatively if you can use a pipe instead of msgQ, you could potentially use select.

As another alternative, perhaps consider having multiple tasks, each servicing a single msgQ

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top