• <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 閱讀(2099) 評論(0)  編輯 收藏 引用 所屬分類: C++并發和并行 concurrency & parallelism

            <2011年4月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产高潮国产高潮久久久| 国产成人精品综合久久久久 | 久久久久久a亚洲欧洲aⅴ| 久久亚洲AV成人无码| 亚洲一区精品伊人久久伊人 | 久久中文字幕人妻丝袜| 亚洲国产精品成人久久蜜臀| 亚洲AV伊人久久青青草原| 青春久久| 久久SE精品一区二区| 久久国产精品成人影院| 久久精品国产亚洲精品2020| 国产情侣久久久久aⅴ免费| 狠狠色婷婷综合天天久久丁香 | 国产高潮国产高潮久久久91| 一本大道加勒比久久综合| 久久er国产精品免费观看8| 无码乱码观看精品久久| 亚洲国产成人久久综合野外| 伊人久久大香线蕉亚洲五月天| 久久久久99精品成人片试看| 嫩草影院久久国产精品| 久久国产视频99电影| 久久久亚洲欧洲日产国码是AV | 久久久久国产一级毛片高清版| 国产精品VIDEOSSEX久久发布| 亚洲а∨天堂久久精品| 青草国产精品久久久久久| 青青草原综合久久| 综合久久精品色| 成人久久久观看免费毛片| 日韩欧美亚洲国产精品字幕久久久| 久久久久波多野结衣高潮| 久久无码av三级| 青青草原综合久久大伊人| 99久久er这里只有精品18| 久久久久亚洲精品男人的天堂| 亚洲欧洲日产国码无码久久99| 国产无套内射久久久国产| 无码人妻久久一区二区三区免费 | 久久精品国产色蜜蜜麻豆|