• <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)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久久久久久久中文字幕 | 久久亚洲精品无码aⅴ大香| 久久久久国产一区二区三区| 国产精品99久久久久久猫咪 | 亚洲AV无码久久精品成人| 国产精品久久久久久吹潮| 国产成人精品综合久久久| 久久久免费观成人影院| 欧美牲交A欧牲交aⅴ久久| 国产69精品久久久久99尤物| 亚洲精品乱码久久久久久按摩| 久久国产精品99久久久久久老狼 | 亚洲AⅤ优女AV综合久久久| 久久国产色av免费看| 99久久www免费人成精品| 无码任你躁久久久久久老妇App| 久久久国产乱子伦精品作者| 久久无码人妻精品一区二区三区 | 手机看片久久高清国产日韩| 久久久久久久久久久久中文字幕| 人人狠狠综合88综合久久| 久久亚洲国产午夜精品理论片 | 2020最新久久久视精品爱 | 国内精品久久久久影院优| 亚洲精品无码专区久久同性男| 久久免费精品一区二区| 久久狠狠高潮亚洲精品| 亚洲精品蜜桃久久久久久| 亚洲国产香蕉人人爽成AV片久久 | 亚洲人成网站999久久久综合| 久久伊人精品青青草原高清| 色综合久久无码中文字幕| 亚洲中文字幕伊人久久无码| 久久久久国产精品三级网| 久久精品国内一区二区三区| 国产精品久久网| 99久久精品免费看国产免费| 99久久婷婷国产一区二区| 狠狠色丁香婷综合久久| 国产一区二区精品久久| 久久精品一区二区三区不卡|