Destruction of Native Objects with Static Storage Duration

前端 未结 2 1201
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 23:45

2012-12-09 Summary:

  • In a normal mixed-mode application global native C++ destructors run as finalizers. It\'s not possible to change that beha
2条回答
  •  盖世英雄少女心
    2020-12-31 00:32

    To answer the "Where is this documented / how can I educate myself more on the topic?" question: you can understand how this works (or used to work at least for the framework 2) if you download and check out the Shared Source Common Language Infrastructure (aka SSCLI) from here http://www.microsoft.com/en-us/download/details.aspx?id=4917.

    Once you've extracted the files, you will find in gcEE.ccp ("garbage collection execution engine") this:

    #define FINALIZER_TOTAL_WAIT 2000
    

    wich defines this famous default value of 2 seconds. You will also in the same file see this:

    BOOL GCHeap::FinalizerThreadWatchDogHelper()
    {
        // code removed for brevity ...
        DWORD totalWaitTimeout;
        totalWaitTimeout = GetEEPolicy()->GetTimeout(OPR_FinalizerRun);
        if (totalWaitTimeout == (DWORD)-1)
        {
            totalWaitTimeout = FINALIZER_TOTAL_WAIT;
        }
    

    That will tell you the Execution Engine will obey the OPR_FinalizerRun policy, if defined, which correspond to the value in the EClrOperation Enumeration. GetEEPolicy is defined in eePolicy.h & eePolicy.cpp.

提交回复
热议问题