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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久婷婷午色综合夜啪| 精品久久久中文字幕人妻| 久久精品一区二区| 久久亚洲国产欧洲精品一 | 久久婷婷五月综合色99啪ak| 久久国产午夜精品一区二区三区| 一级女性全黄久久生活片免费| 色综合久久中文字幕无码| 久久99久久99精品免视看动漫| 一级做a爰片久久毛片16| 久久久黄色大片| 午夜不卡888久久| 久久人做人爽一区二区三区| 免费精品99久久国产综合精品| 综合久久给合久久狠狠狠97色| 久久久久亚洲AV无码专区体验| 国产精品久久久久久久午夜片| 亚洲乱码精品久久久久..| 亚洲国产天堂久久久久久| 亚洲乱亚洲乱淫久久| 人妻久久久一区二区三区| 国产精品亚洲综合久久| 国产女人aaa级久久久级| 国内精品久久久久久久97牛牛| 国产精品久久新婚兰兰| 久久久久亚洲?V成人无码| 亚洲一区中文字幕久久| 精品久久久久香蕉网| 久久久无码精品亚洲日韩京东传媒| 久久国产成人午夜AV影院| 潮喷大喷水系列无码久久精品 | 狠狠色噜噜色狠狠狠综合久久| 久久黄视频| 久久精品国产99久久丝袜| 亚洲国产成人久久综合一| 国产综合久久久久久鬼色| 99久久久精品免费观看国产| 久久不见久久见免费视频7| 久久99亚洲网美利坚合众国| 国产婷婷成人久久Av免费高清| 国内精品久久久久伊人av|