Blocking caused by the use of critical_section in the main thread

Source: Internet
Author: User
The recently written Program has a small problem. MessageBox is used in a certain place. If you click OK quickly, the whole program will not respond. because it is not a crash, it is considered a deadlock. later I used log and found the problem. Let's take a look at Log File: Time at: 0004234132 line: 0 adddownloadtaskready enter criticaltime at: 0004234194 line: 1 adddownloadtaskready leave criticaltime at: 0004234803 line: export ready enter criticaltime at: 0004234803 line: 3_fddownloadresultcallbackinclass enter criticaltime at: 0004236207/* message box ("here"); */line: 4 adddownloadtaskready enter criticaltime at: 0004243398 line: 5 call downloadresult js fn/* sendmessage (...); */

We can see that after line: 4, adddownloadtask has not entered critical, but has been waiting. because adddownloadtask is a function called by the main thread, it has been waiting for _ fddownloadresultcallbackinclass to exit critical, but _ fddownloadresultcallbackinclass is displaying MessageBox, so the main thread is blocked! After clicking OK MessageBox, The _ fddownloadresultcallbackinclass executes the last step to send a message, but the main thread is still blocked at this time, so the sendmessage remains waiting for the main thread to return sendmessage, so everyone will continue to consume it. to put it simply: 1. enter critical, pending, 2. at this time, other functions will enter critical, wait, and cause the main thread to Block 3. 1. After Entering critical, after a period of suspension, the suspension is lifted. sendmessage (note not postmessage) 4. because the main thread is blocked, sendmessage cannot be sent, and 1 cannot exit critical5. overall blocking.

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: 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.