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

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

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久人人青草97香蕉| 热re99久久精品国99热| 久久国产免费直播| 亚洲精品成人久久久| 久久久久亚洲av无码专区| 青青青青久久精品国产h| 亚洲精品第一综合99久久| 久久久久久人妻无码| 国产午夜福利精品久久| 久久精品国产亚洲av麻豆图片| www性久久久com| 日韩久久久久中文字幕人妻| 东京热TOKYO综合久久精品| 国产精品久久久久a影院| 91精品国产综合久久精品| 欧美日韩中文字幕久久久不卡| 久久婷婷五月综合97色一本一本 | 久久996热精品xxxx| 久久亚洲精品国产精品| 久久免费视频一区| 久久高潮一级毛片免费| 91精品国产乱码久久久久久 | 国产精品久久久久AV福利动漫| 久久综合色区| 国产精品亚洲综合专区片高清久久久 | 亚洲国产欧洲综合997久久| 久久露脸国产精品| 国内精品久久久久影院网站| 久久精品成人免费网站| 亚洲精品无码专区久久久| 奇米影视7777久久精品人人爽| 久久久久国色AV免费看图片| 99久久伊人精品综合观看| 日本一区精品久久久久影院| 国产产无码乱码精品久久鸭 | 精品少妇人妻av无码久久| 久久午夜伦鲁片免费无码| 精品久久久久久国产潘金莲| 国产人久久人人人人爽| 亚洲国产精品一区二区久久| 国产福利电影一区二区三区久久久久成人精品综合 |