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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            无夜精品久久久久久| 97久久精品无码一区二区天美| 99久久做夜夜爱天天做精品| 日本欧美国产精品第一页久久| 免费一级欧美大片久久网| 久久精品亚洲AV久久久无码| 国产福利电影一区二区三区久久久久成人精品综合 | 少妇久久久久久被弄高潮| 99国内精品久久久久久久| 久久AV高潮AV无码AV| 国产精品久久久久久久| 亚洲AV伊人久久青青草原| www久久久天天com| 日本强好片久久久久久AAA| 日日狠狠久久偷偷色综合免费| 日韩精品久久无码人妻中文字幕 | 久久婷婷人人澡人人爽人人爱| 丰满少妇高潮惨叫久久久| 最新久久免费视频| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久综合色区| 久久国产精品久久精品国产| 色偷偷偷久久伊人大杳蕉| 久久精品国产第一区二区| 99久久成人18免费网站| 三上悠亚久久精品| 久久久久亚洲av成人网人人软件 | 久久婷婷五月综合97色| 模特私拍国产精品久久| 日本欧美国产精品第一页久久| 久久精品视频免费| 99热成人精品热久久669| 久久人人爽人人爽人人AV| 日韩久久无码免费毛片软件| 蜜桃麻豆www久久| 精品久久久久久国产牛牛app| 久久久精品久久久久久| 91久久成人免费| 国产成人久久精品二区三区| 国产精久久一区二区三区| 国产高潮国产高潮久久久91 |