A series of graphs--why the thread was created in DllMain and wait will be stuck

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.