LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW & MVTec Halcon

Solved!
Go to solution
Solution
Accepted by topic author dadreamer

MTrivedi

Great news for you! Cat Very Happy After I have done some tests on Halcon 13, I've re-read the manuals and saw this:


HALCON Programmer's Guide:

3.2 Terminate HALCON Library

 

In applications where DLLs are unloaded in a thread-exclusive context (such as applications using COM), the HALCON library will not terminate properly if the thread pool is still active, except when using the HALCON/COM interface.

 

A possible scenario where the problem may occur is, e.g., when using HALCON/C++ to implement an ATL control.

 

To overcome this problem, it is necessary to call the function FinalizeHALCONLibrary() before unloading the DLL. Make sure that the call to FinalizeHALCONLibrary() is not from within any other DLL’s DllMain function. Please note that once FinalizeHALCONLibrary() has been called, no further HALCON functions may be called.


And here's the quote from Release Notes for HALCON 13.0.1:


Since HALCON 12.0.2, the mechanism to terminate the HALCON library has been changed by introducing a new function FinalizeHALCONLibrary(). Now, the correct way to close all HALCON threads and free resources is to call the function FinalizeHALCONLibrary() before unloading halcon.dll. The Programmer's Guide missed this information. This problem has been fixed.


So, sometimes it's worth reading manuals and developer's notes to know the way our software works flawlessly. Cat Embarassed

0 Kudos
Message 41 of 63
(6,037 Views)

Thank you ☺️ 

So I have to update the halcon version from 13.0 to 13.0.1?

0 Kudos
Message 42 of 63
(6,017 Views)

@MTrivedi wrote:

Thank you ☺️ 

So I have to update the halcon version from 13.0 to 13.0.1?


You already have this func available starting from Halcon 12.0.2. But if you are interested in improvements and bugfixes, then it's better to install the recent version (see Release Notes).

0 Kudos
Message 43 of 63
(6,000 Views)

Thank you dadreamer. 

It's working now nicely

 

I have one another question it that , when I am call this dll multiple times parallel , it takes more process time , so I try to set my dll as a reentrant but it can't work

0 Kudos
Message 44 of 63
(5,979 Views)

MTrivedi wrote:

I have one another question it that , when I am call this dll multiple times parallel , it takes more process time , so I try to set my dll as a reentrant but it can't work


Well, I'm not sure for 100% but I think, you should move to 64-bit LabVIEW, Halcon and write 64-bit DLL. If you set CLFN as running in any thread and you're sure that your code is able to run reentrantly (no global vars etc.) it likely goes to threading issues. Because you work in 32-bit environment, you don't have "real" parallelization between the threads. Your program uses one processor core and all the threads run sequentially by interruption. To have all the cores involved into the task you definitely should try 64-bit software.

0 Kudos
Message 45 of 63
(5,971 Views)

@dadreamer wrote:

MTrivedi wrote:

I have one another question it that , when I am call this dll multiple times parallel , it takes more process time , so I try to set my dll as a reentrant but it can't work


Well, I'm not sure for 100% but I think, you should move to 64-bit LabVIEW, Halcon and write 64-bit DLL. If you set CLFN as running in any thread and you're sure that your code is able to run reentrantly (no global vars etc.) it likely goes to threading issues. Because you work in 32-bit environment, you don't have "real" parallelization between the threads. Your program uses one processor core and all the threads run sequentially by interruption. To have all the cores involved into the task you definitely should try 64-bit software.


That doesn't quite sound right. 32 bit processes can just as well use parallel threads that get distributed on multiple cores if the software in question allows that. 64 bit processes mainly profit from a linear virtual address space that goes beyond 4GB if that much physical memory is available. For processing large images that could be a significant benefit.

However I guess the problem here might be the Halcon library which might or might not contain some specific code that makes it single core executable. If that is the case, there is not much you can do from within LabVIEW but you might have to call additional Halcon functions in your DLL to inform the Halcon kernel that it should use multiple cores.

Rolf Kalbermatter
My Blog
0 Kudos
Message 46 of 63
(5,967 Views)

Thank you for clarifying, Rolf!

 

MTrivedi

Take a look at this: http://www.mvtec.com/doc/halcon/13/en/set_system.html

Check these parameters in your current instance:

'use_window_thread'

'parallelize_operators'

'reentrant'

'thread_num' / 'tsp_thread_num'

'thread_pool'

I assume you're not calling any (G)UI-related operators inside your library. May you post all your code here (not in a form of screenshot)?

0 Kudos
Message 47 of 63
(5,960 Views)

Hello dadreamer 

 

I tried this operators , but reentrant and parallelize_operators are by default true . So is it necessary to set it? I tried this but can't show it's effect. I set LabVIEW vi execution in  preallocated clone reentrant execution and my CLFN in UI thread

Download All
0 Kudos
Message 48 of 63
(5,941 Views)

@MTrivedi wrote:

Hello dadreamer 

 

I tried this operators , but reentrant and parallelize_operators are by default true . So is it necessary to set it? I tried this but can't show it's effect. I set LabVIEW vi execution in  preallocated clone reentrant execution and my CLFN in >>>UI thread<<<.


That's the serialization problem then! The UI thread is single threaded and anything that goes through it has to compete for this tread together with other protected operations in LabVIEW such as UI drawing and code sections that NI knows can't be made multi-threading safe without an enormous overhead.

 

But setting it to any thread, while allowing parallel execution can be a tricky setting. You have to be absolutely sure that the external code you call is fully multi-threading safe. That means among a few other things: no global variables or other global resources (like hardware or other IO devices) being called from anywhere in that external code that can be called in parallel, unless these resources are properly protected through a semaphore or similar. That includes your self written code as well as any other function you may call from any third party library. If the documentation to a library or particular function doesn't state that it is safe to call it in parallel with itself or other functions from the library it is usually a dangerous thing to assume that you can!

Rolf Kalbermatter
My Blog
0 Kudos
Message 49 of 63
(5,933 Views)

Hello Rolf 

 

You are right but if I am using CLFN as a "run in any thread" then again old error of 9700 and hanging issue occured

0 Kudos
Message 50 of 63
(5,931 Views)