From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Create thread only works once.

Hello.

 

I want to launch some functions in different threads. Every function finish executing before the next one starts.

Each of these functions are launching through a single function pointer.

 

It does sound simple, but it is working only the first time. Afther that, I get an error (unfortunately I don't remember the error, something like "non debuggable program").

 

Here is the piece of code:

 

FuncPtrDouble = GetExternalModuleAddr(TestID, FuncName, &status);

if ( FuncPtrDouble != NULL)

{

//status = (*FuncPtrDouble)(&Result);   //This one works everytime.

 

CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, (*FuncPtrDouble)(&Result), NULL, &functionId); //Executes only once. Second time crushes.

 

CmtWaitForThreadPoolFunctionCompletion(DEFAULT_THREAD_POOL_HANDLE, functionId, 0);

CmtReleaseThreadPoolFunctionID(DEFAULT_THREAD_POOL_HANDLE, functionId);

}

0 Kudos
Message 1 of 4
(4,406 Views)

Actually, I made a mistake.

 

It does not crash the second time but the first time. And here I have a question.

 

My initial impression was that, since this is a thread, it runs parallel with the main program.

Here, when we step in CmtScheduleThreadPoolFunction, the main program freezes!

 

After it executes, the program crashes in the CmtWaitForThreadPoolFunctionCompletion.

 

So, I have two questions:

 

1. Why doesn't the the new thread run in parallel with the main program?

2. Why does it crush in the CmtWaitForThreadPoolFunctionCompletion?

 

Help?

 

Thanks,

Vasileios.

0 Kudos
Message 2 of 4
(4,388 Views)

Update.

 

Since I focus my problem in the specific function, I searched NI forums again and found this thread:

http://forums.ni.com/t5/LabWindows-CVI/CmtWaitForThreadPoolFunctionCompletion-Problems/m-p/1461920/h...

 

And, while I do not have an RT system (my cRIO runs embedded windows), I replaced the DEFAULT_THREAD_POOL with the RUN_IN_SCHEDULED_THREAD and it works now. I mean that it doesn't crash.

 

But it is still not running in parallel.

 

Any ideas just for problem number 2?

Thanks.

0 Kudos
Message 3 of 4
(4,384 Views)

Never mind, solved it.

 

I had many problems but figured it out as soon as I read the NI functions guide.

 

RTFM!!!!

0 Kudos
Message 4 of 4
(4,377 Views)