LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use a thread safe queue to store strings

I am looking for an example on how to use a thread safe queue in LabWindows CVI to store strings. The use case is to use a primary thread to receive status messages (data acquisition) and store each message in a thread safe queue, and a secondary thread to retrieve the message strings from the queue to display the messages to the user using a panel. I understand the concept of the queue, as well as the example code that illustrate the use of queues with simple data types such as doubles. Strings are a little trickier because of their similarity to arrays. So I guess an example showing the use of queues with arrays of data would do too. 
 
Thanks. 
0 Kudos
Message 1 of 3
(3,327 Views)

In Ansi C as string is nothing else then a array of characters, so you can use the example that you already cknow and simply change the datatype from double to char, then it should work.

 

0 Kudos
Message 2 of 3
(3,315 Views)
I would be inclined to malloc() some storage space for each string (remember the null at the end!), put the string in it, then put the pointer to the storage in the queue. The thread retrieving the pointer could then do what it liked with the data and finally free() the storage space.


Martin.

--
Martin
Certified CVI Developer
0 Kudos
Message 3 of 3
(3,310 Views)