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

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

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品成人欧美大片| 99久久免费只有精品国产| 久久天天躁狠狠躁夜夜不卡| 久久免费国产精品| 欧美亚洲国产精品久久| 久久乐国产综合亚洲精品| 99久久香蕉国产线看观香 | 精品久久久久久久久久久久久久久 | 亚洲精品白浆高清久久久久久| 新狼窝色AV性久久久久久| 久久精品人人槡人妻人人玩AV | 国产亚州精品女人久久久久久 | 久久精品视屏| 久久久久久久久久久| 久久国产免费观看精品3| 国产精品99久久不卡| 精品久久久久久无码不卡| av国内精品久久久久影院| 久久精品国产国产精品四凭| 精品无码久久久久国产动漫3d| 久久精品国产亚洲麻豆| 久久伊人精品一区二区三区| 久久精品成人国产午夜| 精品国产乱码久久久久久呢| 中文精品久久久久国产网址| 久久中文字幕精品| 色综合久久综精品| 五月丁香综合激情六月久久| 久久久精品波多野结衣| 久久99国产综合精品免费| 久久国产成人午夜aⅴ影院| 久久香蕉超碰97国产精品| 性高湖久久久久久久久AAAAA| 欧美亚洲国产精品久久蜜芽| 久久成人小视频| 无码精品久久一区二区三区| 麻豆精品久久久一区二区| 97精品国产91久久久久久| 综合久久国产九一剧情麻豆 | 热99RE久久精品这里都是精品免费| 亚洲国产精品久久|