This is an old topic, recommend an article:
Http://blog.csdn.net/breaksoftware/article/details/8150476#0-tsina-1-83826-397232819ff9a47a7b7e80a40613cfe1
Here's a simple drawing to illustrate the core problem:
The key is ntdll!. Ldrploaderlock this lock.
1. The current thread acquires this lock before using Dll_process_attatch to enter DllMain.
2, if the thread is created inside the DllMain, the new thread will get the lock during the initialization process.
3, if only createthead returns, the current thread will soon release the lock, and then the newly created thread will be able to successfully obtain the lock.
4, but if CreateThread later uses wait waits for the thread to end, then the current thread does not release ldrploaderlock, the new thread is not available, and goes into wait. Will cause the card to die.
Therefore, it is best not to create a thread in DllMain, even if it is created, never wait.
Finally, a picture to see the relationship (picture right-click new tab opens to see the full HD large picture):
A series of graphs--why the thread was created in DllMain and wait will be stuck