> do I have to concern about concurrent access when using a queue (multiple > writers, single reader), i. e. do I have to implement mutual exclusions > (semaphores) before and after writing to and reading from the queue. >
The answer depends upon the type of operation you are performing on the queue. Reads, writes, clears, and all the ready-built operations for queues already have the required protection built-in. For a situation where there might need to be additional protection, assume you hae multiple readers, and for some reason you have different elements being written to the queue. One element, the count element, describes the number of additional data elements to be read. You would probably want a single loop to read the count element, then read that many data elements, then release so that the other readers could take their sequence. You wouldn't want the readers to interleave any finer grained than that or the count and data elements would be jumbled and the readers would confuse one another. Of course I'd argue that this is a bad usage of a queue, and the count and data elements should probably be placed in multiple queues or bundled in to a single queue element. But for argument's sake, if this is the way the queue is being used, you would want to acquire a semaphore, then read the sequence, then release. Or call a single subVI to do this and return. Since you can only have one going on and a subVI that isn't reentrant services one at a time, it is cleaner than the semaphores. So the summary is for normal usage, no extra work needed, for more complicated usages, you can add some simple protection like a subVI wrapper or semaphores or ... Greg McKaskle
