LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

second thread does not open

Hi,
 
I wrote a program that open a second thread and while it runs the main thread to something else... the main thread does not exit until the second thread returns.
it looks something like that:
void DLLEXPORT myFunctionName(char* scriptName, tTestData* testData)
{
  ....
     CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE,
                 newThread,
             (void*) command,NULL);
 while(flag)
 {
....
 } 
}
the function of the thread is:

int CVICALLBACK newThread(void *functionData)
{
 printf("here\n");
 
command = (char*)functionData;
 
 flag= TRUE;
...
 flag= FALSE;
}
 
my problem is that when I call this function from testStand it runs fine for a few time and after a while the second thread will not open anymore until I'll exit testStand completely
after reopenning testStand it will run fine again for a few times...
 
when I say that the secondary thread is not openning - it doesn't print the first line and doesn't return an error code value.
 
if anyone have any ideas...
 
thanks,
 
Noa
0 Kudos
Message 1 of 3
(3,109 Views)
Hi Noa,
 
The number of threads that can be initiated from a thread pool is limited with the number of idle thread available in the pool.
You use the default thread pool, so each time you call CmtScheduleThreadPoolFunction the number of available thread handles from this pool decreases. After enough number of calls you might have consumed them all.
 
In this case CmtScheduleThreadPoolFunction does not return an error but it holds up your request until a thread becomes idle, which happens when your thread function returns.
 
You might create your own thread pool with your choice of number of threads or make sure the started threads end as fast as you create new ones. If you assign an ID for your threads you can wait for them to return before your function call in TestStand returns. So that, when you create a new thread you will be sure that the previous one is terminated.
(see the CmtScheduleThreadPoolFunction help text)
 
Hope this helps.


Message Edited by ebalci on 02-26-2008 05:46 PM
S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 3
(3,093 Views)

hi Noa: 

   if you use testand to call you CVI function, why not use testand multithreading?

 

Sonic



帖子被菊花烧饼在02-26-2008 11:15 PM时编辑过了
Sonic

Diffrent Strokes for Different Folks
0 Kudos
Message 3 of 3
(3,069 Views)