Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLLs and Multithreading...

Status
Not open for further replies.

SWilliams15

Programmer
Dec 28, 2000
14
US

Say I call a DLL function from VB. The DLL func then creates a worker thread. Does that worker thread get destroyed when the DLL is unloaded from memory? I'd say yes since it's running in the same address space. Could someone confirm this?

Thanks,
Sean.
 
My guess would also be "yes". COnsider the scenario where u have a process with n threads. If u delete the process, then all the threads in the process will automatically be deleted.

Sriks
 
What if the process didn't end but just unloaded the DLL?

-pete
 
SWilliams -

If having the thread end when the DLL unloads is what you want, then I'd put code in the DLLMain function to detect this (look for DLL_THREAD_DETACH and DLL_PROCESS_DETACH).

Otherwise, I think the thread will continue running until the parent process ends.

Chip H.
 
I agree with Chip. Also ending threads when the process is going to continue can cause problems if not done correctly. Read the MSND Articles that discuss exiting threads.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top