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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            成人国内精品久久久久影院VR| 色青青草原桃花久久综合| 97久久综合精品久久久综合| 久久精品视频网| 久久人搡人人玩人妻精品首页| 久久无码中文字幕东京热| 久久婷婷五月综合97色一本一本 | 精品无码久久久久久久动漫 | 久久综合亚洲色HEZYO社区| 中文字幕久久精品无码| 久久久久久综合一区中文字幕| 伊人久久大香线蕉无码麻豆| 狠狠色婷婷综合天天久久丁香| 一本色道久久综合狠狠躁篇| 成人国内精品久久久久一区| 中文字幕无码久久久| 久久香蕉一级毛片| 久久人爽人人爽人人片AV| 久久性生大片免费观看性| 久久66热人妻偷产精品9| 久久亚洲精品无码观看不卡| 国产成人精品久久二区二区| 久久久久久久久久久精品尤物 | 久久人人爽人人爽人人片AV东京热| 久久综合综合久久综合| 性做久久久久久久久| 久久精品国产清自在天天线| 狠狠色婷婷综合天天久久丁香| 无码专区久久综合久中文字幕| 青春久久| 色综合久久久久综合99| 久久久久久毛片免费看| 狠狠色伊人久久精品综合网| 国产欧美一区二区久久| 久久精品国产一区| 老司机国内精品久久久久| 九九久久99综合一区二区| 国产精品久久亚洲不卡动漫| 久久w5ww成w人免费| 国产精品毛片久久久久久久| 久久青青草原综合伊人|