• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ library系列 -- static destructors in multiple threads

              In VC++ 8.0, while  code compiled with /clr or /clr:pure, static destructors sometimes would not being properly called before process exites in multiple threads.

              CRT incorrectly set a lock at _global_unlock which resulted in such issue.

              In CLR-mixed mode, during the inialization of static local object, CRT would call _atexit_m(_CPVFV func) in msilexit.cpp to register a special __clrcall callback function which would be called back to destroy such static object when the current AppDomain quited.

              In the multithread environment, _atexit_helper which was invoked by _atexit_m, could register such callbace function successfully because it had been guarded by __global_lock() and __global_unlock(). But in the same environment, the _atexit_m would fail to assign the correct value to __onexitbegin_m and __onexitend_m.

              __onexitbegin_m and __onexitend_m were shared by the different threads; It's the key point of such issue. For example, the following statements,

              __onexitbegin_m = (_CPVFV *)_encode_pointer(onexitbegin_m);
              __onexitend_m = (_CPVFV *)_encode_pointer(onexitend_m);

            should also guarded by __global_lock() and __global_unlock() or other syn primitives.


            __global_lock();
            __onexitbegin_m = (_CPVFV *)_encode_pointer(onexitbegin_m);
            __onexitend_m   = (_CPVFV *)_encode_pointer(onexitend_m);
            __global_unlock();


            extern "C" int __clrcall _atexit_m(_CPVFV func)
            {
             MANAGED_ASSERT(AppDomain::CurrentDomain->IsDefaultAppDomain(), "This fuction must be called in the default domain");

             __global_lock();
             _CPVFV* onexitbegin_m = (_CPVFV*)_decode_pointer(__onexitbegin_m);
             _CPVFV* onexitend_m = (_CPVFV*)_decode_pointer(__onexitend_m);
             __global_unlock();

             int retval = _atexit_helper((_CPVFV)_encode_pointer(func), &__exit_list_size, &onexitend_m, &onexitbegin_m);

             __global_lock();
             __onexitbegin_m = (_CPVFV*)_encode_pointer(onexitbegin_m);
             __onexitend_m  = (_CPVFV*)_encode_pointer(onexitend_m);
             __global_unlock();

             return retval;
            }

            posted on 2011-02-08 20:57 flagman 閱讀(2105) 評論(0)  編輯 收藏 引用 所屬分類: C++并發(fā)和并行 concurrency & parallelism

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲人成无码www久久久 | 久久精品免费一区二区| 久久精品麻豆日日躁夜夜躁| 婷婷伊人久久大香线蕉AV| 久久精品国产精品亚洲精品| 精品欧美一区二区三区久久久| 色欲综合久久躁天天躁| 久久精品国产第一区二区三区| 国产精品青草久久久久福利99 | 伊人久久五月天| 久久精品a亚洲国产v高清不卡| 国产成人AV综合久久| 伊人久久精品无码av一区| 精品久久久久久久久久久久久久久 | 久久精品国产精品亚洲精品| 性做久久久久久久久老女人| 亚洲精品无码久久久久久| 欧美精品一区二区久久| 久久精品视频免费| 久久久女人与动物群交毛片| 青草久久久国产线免观| 国产香蕉97碰碰久久人人| 成人国内精品久久久久一区| 伊人久久精品无码二区麻豆| 久久亚洲精品无码aⅴ大香| 久久精品无码一区二区app| 国产精品成人精品久久久| 久久精品国产一区| 久久99热精品| 国产一级做a爰片久久毛片| 国产精品99久久99久久久| 五月丁香综合激情六月久久| 99久久99久久精品国产片果冻| 久久最近最新中文字幕大全 | 三级片免费观看久久| 99久久婷婷国产一区二区| 色综合久久88色综合天天| 一本色道久久88加勒比—综合| 久久成人精品视频| 国产综合免费精品久久久| 国产亚洲美女精品久久久|