01-15-2010 10:53 AM
I have a thread safe queue active in my program. It is being accessed in different locations at different times. Since it is a thread safe queue shoudnt the other areas prevent access or wait till the read or write into the queue is done before accessing the TSQ again? What does this error message mean and how do I resolve the conflict and actually use the TSQ the way it is supposed to be used.
01-15-2010 11:43 AM
This error is returned when two threads simultaneously attempt to read (or get the read pointer) from the queue. There is a similar protection for two threads simultaneously writing to the queue. The primary reason for this is to prevent interleaving or disruption of data chunks. In your scenario, you could solve the problem by putting your reads in a while loop, where you keep retrying the read if error -14911 is returned. I would first take another look at the program, though, and decide whether it really makes sense to have multiple readers (or writers) for the same queue. If there are different types of data, you might want separate queues for each type of data.
Mert A.
National Instruments
01-07-2011 06:44 AM
Hi mdmorar,
This reply may be a little (almost a year ) late, but I thought it should not be left unclear.
The help text for CmtNewTSQ states that: "You can use a thread safe queue to safely pass data between two threads. You can use one thread to write data into the queue and another thread to read data from the queue."
So, you can have one write and one read pointer. The TSQs can manage simultaneous requests for writing and reading, but cannot handle 2 reading or 2 writing threads. Both generate an error.
The reason I ran into this topic was the same as yours. I got the same error code and after a few minutes of help search I got my answer.
I had thought TSQs could handle multiple writers and readers, but apparently they cannot.
I think, the correct solution is to either follow Mert's suggestion or use Thread-Safe Variables.
Am I right Mert?