• <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++并發和并行 concurrency & parallelism

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久香蕉国产线看观看猫咪?v| 天天久久狠狠色综合| 亚洲精品tv久久久久久久久久| 久久精品九九亚洲精品天堂| 狠狠综合久久综合中文88| 午夜精品久久久久久久无码| 久久国产免费观看精品3| 久久久久久久综合日本| 久久久一本精品99久久精品88| 看久久久久久a级毛片| 精品久久久久久久中文字幕| 7777精品久久久大香线蕉| 久久婷婷久久一区二区三区| 综合久久一区二区三区| 91精品国产综合久久四虎久久无码一级 | 无码八A片人妻少妇久久| 久久婷婷五月综合97色| 久久久久99精品成人片牛牛影视| 久久人人爽人人爽人人片AV麻豆| 久久久久精品国产亚洲AV无码| 丰满少妇高潮惨叫久久久| 久久精品青青草原伊人| 亚洲国产小视频精品久久久三级| 精品无码久久久久国产| 77777亚洲午夜久久多喷| 久久国语露脸国产精品电影| 亚洲国产精品无码久久九九| 日日狠狠久久偷偷色综合免费| 国产精品视频久久| 久久精品亚洲日本波多野结衣| 国产高潮国产高潮久久久| 久久人爽人人爽人人片AV| 久久久久国产精品嫩草影院| 久久综合久久综合亚洲| 久久综合亚洲色HEZYO社区| 久久久国产视频| 国产精品久久久香蕉| 色婷婷综合久久久久中文| 久久ww精品w免费人成| 色综合色天天久久婷婷基地| 9191精品国产免费久久|