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

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久人人爽人爽人人爽av| 久久精品国产国产精品四凭| 国产成人精品久久| 成人久久精品一区二区三区| 久久九九亚洲精品| 国内精品久久久久影院老司| 亚洲AV日韩AV天堂久久| 久久久国产精品福利免费| 美女久久久久久| 久久精品国产亚洲av麻豆色欲| 久久国产精品99久久久久久老狼 | 久久精品水蜜桃av综合天堂| 久久精品国产精品青草app| 一级女性全黄久久生活片免费| 久久久久99精品成人片试看 | 欧美久久精品一级c片片| 武侠古典久久婷婷狼人伊人| 69国产成人综合久久精品| 亚洲人AV永久一区二区三区久久| 久久91亚洲人成电影网站| 色婷婷久久综合中文久久蜜桃av| 色诱久久av| 久久久久久国产精品无码下载| 九九久久自然熟的香蕉图片| 久久99九九国产免费看小说| 久久伊人影视| 久久精品亚洲精品国产欧美| 一级做a爰片久久毛片人呢| 日产精品99久久久久久| 无码精品久久久久久人妻中字| 久久只这里是精品66| 亚洲国产精品成人久久蜜臀| 91精品国产色综久久| 国产69精品久久久久99尤物| 久久综合综合久久97色| 久久久精品一区二区三区| 99精品久久精品一区二区| 色噜噜狠狠先锋影音久久| 免费精品99久久国产综合精品| 久久精品国产亚洲综合色| 国产ww久久久久久久久久|