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

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久亚洲AV成人无码软件| 伊人精品久久久久7777| 久久综合九色综合网站| 久久久亚洲欧洲日产国码是AV| 久久精品人人做人人妻人人玩 | 少妇久久久久久被弄高潮| 亚洲中文久久精品无码ww16| 精品少妇人妻av无码久久| 精品国产综合区久久久久久| 日韩久久久久中文字幕人妻| 色综合久久久久综合体桃花网| 日本久久久精品中文字幕| 亚洲精品无码久久毛片| 久久精品亚洲日本波多野结衣 | 国产无套内射久久久国产| 久久久久人妻一区二区三区| 免费观看久久精彩视频| 亚洲国产成人精品女人久久久 | 91久久精品91久久性色| 午夜视频久久久久一区 | 国产精品久久网| 国内精品久久久久影院薰衣草| 精品久久一区二区| 亚洲午夜久久久久久久久久| 精品久久久久久国产三级| 国产成人精品久久一区二区三区| 亚洲伊人久久成综合人影院 | 色婷婷久久久SWAG精品| 精品国产乱码久久久久久1区2区 | 国产99久久精品一区二区| 亚洲愉拍99热成人精品热久久| 一本久久免费视频| 欧美国产成人久久精品| 国产精品欧美久久久久天天影视| 国内精品久久人妻互换| 久久久女人与动物群交毛片| 久久精品国产清自在天天线| 思思久久99热只有频精品66| 久久国产成人午夜AV影院| 国产99久久久国产精免费| 嫩草影院久久99|