LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

rs232 and multithreading

Hi to all,

I have a question about multithreading and rs232 communication.
I must be sure that during buffer sending the scheduler doesn't suspend the trasmission thread and executes another one
(the target returns me timeout error when it happens);
all the other threads can be executed only AFTER the end of the buffer transmission.

I know that sending a buffer taker me less than 0.1 second,
so I wonder if I could set high priority for the transmission thread.
Is it ok?

Thanks in advance

Using CVI 6.0 on WinXP
Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 1 of 2
(3,162 Views)
vix -

It won't be one of your threads that pre-empts, since the NI rs-232 library is thread safe, and if one of your other threads does manage to get scheduled, it will be suspended when it runs into the synchronization mechanism inside the library (probably a mutex).  But if the OS decides to run another thread, you could get suspended.

You can create the transmission thread "suspended" so that you can get its handle and boost its priority before letting it start.

If the transmission thread runs infrequently, or completes quickly and then suspends itself, realtime priority could work.  If you put a lot of "stuff" into the transmission thread, you run the risk of priority inversion, thread starvation, fatal embrace, or some other malady.  100 msec shouldn't be a problem.

The Win32 SDK has all the info you need about setting priorities.  Note that the scheduling algorithm varies by OS - WinXP's is a little different from Win 2K's, etc.  I can point you more directly if you like.

You probably want to eliminate the output queue if you can (queue size of -1 in OpenComConfig).

And bear in mind that the NI rs-232 library runs on top of the native Win32 serial driver for everything except one of the newer NI serial boards, as far as I know.  We use the NI 8431 and it uses a new N.I. kernel mode driver, rather than the native Win32 driver.   So if the native driver decides to suspend for whatever reason, you'd be hard put to do anything about it.

Hayes




0 Kudos
Message 2 of 2
(3,141 Views)