LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Free a thread resource in cvi programming

Hi ,

There are two questions to consult . For TCP/IP programming , using RegisterTCPServer() to register an program as a listener ,once there is a connecting request, the listener can create another thread
which also use RegisterTCPServer() to register itself as a new TCP server ,and at the same time ,add its thread ID into a list queue ,so there may be many threads performing different tasks . My questions are :

1.If one thread has finished its task ,how to notify the main thread so that stop the thread and free the resource ?

2.Do I need to use a thread lock with such an application ?

Thanks .

David Lee

liwcwx@public.xm.fj.cn
0 Kudos
Message 1 of 2
(2,855 Views)
If you are using CVI's thread functions (CmtScheduleThreadPoolFunction) to create the threads, you don't have to do any cleanup. When the thread function completes then that thread will go back to idle and can be used by other functions.

You would use a thread lock if you want the main thread to be suspended and waiting on some action in the other thread or for it to shutdown.

One other note, it is kind of rare to be calling RegisterTCPServer() multiple times in a program. You can do it, as long as you register the server on a different port each time, but you may not need to do this. What is your motivation for spawning new threads with different TCP port communications? It most cases, you can use on RegisterTCPServer and have multiple clients
connect and communicate through the Server callback events.

Best Regards,

Chris Matthews
National Instruments
Message 2 of 2
(2,854 Views)