LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to run two functions in parellel

hello all,

I am using Labwindows to store the data to a file , which is sent continueously from microcontroller to PC via USB (Byte by Byte) .

I am copying the data to a ring buffer (PC side)and at the same time I want to write the data to a file without disturbing the process copying to ring buffer.

I tried with Multithread functions ,but when it jumps in between those functions(ex. first threadfunction is copying the data continueously to ring buffer and 2ndthread function is writing data to file) ,they are not synchronised and I am loosing the data because of overflowing of ring buffer.

If I write the data to file with in the loop of copying to ring buffer, I loose the time for writing data to file i.e receiving data continueously from controller will be slow.

please suggest me to run both functions synchronously .



thank you


raj
0 Kudos
Message 1 of 2
(2,909 Views)
Rajj,

Try keeping your program multithreaded but using a thread safe queue.

See the following functions:
CmtNewTSQ
CmtWriteTSQData
CmtReadTSQData

The correct use of these functions will allow your ring control thread to continuously poll for data and then flush it out of the queue when it is done. In the meantime, your USB thread can be gathering more data, and once the ring control thread is done reading and flushing, the USB thread can put more data into the queue.
0 Kudos
Message 2 of 2
(2,901 Views)