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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            欧美久久久久久午夜精品| 精品久久久噜噜噜久久久| 色婷婷噜噜久久国产精品12p| 久久午夜无码鲁丝片午夜精品| 国内精品久久久久影院亚洲| 久久99国产综合精品| 伊人久久大香线蕉综合5g| 国产精品久久久久9999| 中文字幕精品久久| 日韩精品国产自在久久现线拍 | 狠狠色伊人久久精品综合网 | 久久久这里有精品中文字幕| 亚洲女久久久噜噜噜熟女| 91精品国产高清久久久久久国产嫩草| 伊人久久五月天| 国产精品成人久久久久三级午夜电影 | 97久久精品午夜一区二区| 亚洲国产成人久久综合一区77| 国产欧美久久一区二区| 久久久噜噜噜久久熟女AA片| 香蕉久久久久久狠狠色| 欧美一级久久久久久久大| 久久精品国产91久久综合麻豆自制| 99久久国产综合精品女同图片| 国产精品免费久久久久电影网| 久久青青草原综合伊人| 久久99免费视频| 国产成人无码精品久久久久免费| 成人资源影音先锋久久资源网| 久久99亚洲网美利坚合众国| 久久精品欧美日韩精品| 久久久久99精品成人片试看 | 久久高清一级毛片| 久久久久国产一区二区| 久久久久亚洲精品天堂久久久久久| 欧美激情精品久久久久| 国产精品成人久久久久久久| 久久精品成人免费观看97| 一级a性色生活片久久无少妇一级婬片免费放| 久久精品国产一区二区| 人人妻久久人人澡人人爽人人精品|