LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Newly created thread does NOT run!!!

See the attached file.
0 Kudos
Message 1 of 3
(3,545 Views)
Thread will execute, but not until DLL initialization is complete.
0 Kudos
Message 2 of 3
(3,545 Views)
Hello

It is not advisable to do any complex initialization in your DllMain. Dllmain is not reentrant and so your thread wont actaully start until the first PROCESS_ATTACH call to dllmain returns and lets the dll handle the THREAD_ATTACH callback( which is what you are seeing). This is specific to the way Windows loads Dlls.

It is generally not a good thing to do anything of the following inside DllMain:

1) You must never call LoadLibrary or otherwise perform a dynamic bind.

2) You must never attempt to acquire a lock, if that lock might be held by a thread that needs the OS loader lock. (Acquiring a heap lock by calling HeapAlloc or HeapFree is probably okay).

3) You should never call into another DLL. The danger is that the
other DLL may not have initialized yet, or it may have already uninitialized. (Calling into kernel32.dll is okay).

4) You should never start up a thread or terminate a thread, and then rendezvous with that other thread�s start or termination.

Try using a static variable instead to see whether the DllMain was called. Or have another function called by the dll client that would create the thread for you.

Check out the following link for info on this.

And this one too.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 3 of 3
(3,545 Views)