LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Do I need to protect my Rs233 port with a mutex

I will be calling a common transaction function, which uses an open RS232 serial port, from different parts of my code, including several timers. I want only one transaction to be processed at a time. I have a simple flag at the entry of my common transaction function to prevent multiple calls from being processed at the same time.

Is CVI a multithreaded process, especially the timers, that makes it necessary to protect my transaction function using a mutex ?
0 Kudos
Message 1 of 2
(3,088 Views)
A CVI application is not multithreaded unless you make it that way. In order to make an app multithreaded you have to use scheduling functions to spawn new threads other than the one your main function runs in, which is the same thread that the CVI run-time engine runs in. For a better understanding of multithreaded programming read the document entitle "MultithreadingOverview.pdf" found in your ...\cvi\bin directory.

As far as a multithreaded application does go though, yes, you will want to protect the writing and reading of a com port with a thread lock or mutex in order to ensure that what you are getting and sending through the com port is what each thread expects. You can accidentally interleave messages in the com port buffers with multiple accesses from
separate threads.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 2
(3,088 Views)