• <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年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久99精品久久久久久久不卡| 99久久国产综合精品麻豆| 欧美久久一区二区三区| 日韩电影久久久被窝网| 久久久久久亚洲Av无码精品专口 | 久久九九免费高清视频| 亚洲伊人久久综合影院| 国内精品伊人久久久久av一坑 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲国产精品成人久久| 久久精品国产精品国产精品污| 久久综合狠狠综合久久激情 | 国产欧美久久久精品影院| 91久久九九无码成人网站| 久久精品一区二区三区AV| 国内精品久久久久影院网站| 久久久久久久波多野结衣高潮| 99热都是精品久久久久久| 麻豆亚洲AV永久无码精品久久| 久久久久黑人强伦姧人妻| 欧美激情精品久久久久| 久久久久久无码Av成人影院| 久久精品人妻一区二区三区| 久久99国产精一区二区三区| 久久午夜无码鲁丝片| 偷窥少妇久久久久久久久| 无码国内精品久久人妻麻豆按摩| 91精品观看91久久久久久| 成人国内精品久久久久影院| 久久ww精品w免费人成| 精品久久久久久国产潘金莲| 国产成人精品综合久久久久| 四虎久久影院| 午夜精品久久久久久影视777| 93精91精品国产综合久久香蕉| 国产精品99久久免费观看| 婷婷伊人久久大香线蕉AV| 婷婷久久久亚洲欧洲日产国码AV| 久久久精品久久久久影院| 亚洲午夜久久久久久久久久| 久久人人爽人人爽人人AV|