• <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年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            97久久天天综合色天天综合色hd| 91久久婷婷国产综合精品青草| 91久久成人免费| 欧美日韩久久中文字幕| 国产成人无码精品久久久免费| 亚洲国产美女精品久久久久∴| 久久久WWW成人免费精品| 日本精品久久久中文字幕| 久久久久亚洲AV无码网站| 亚洲中文字幕久久精品无码APP| 欧美日韩精品久久久久| 激情久久久久久久久久| 久久久精品人妻无码专区不卡| 亚洲AV无码久久寂寞少妇| 无码任你躁久久久久久久| 热久久国产精品| 精品久久久无码人妻中文字幕豆芽| 亚洲综合精品香蕉久久网| 久久久久久国产精品无码下载| 国产精品久久久久久久| 久久亚洲中文字幕精品有坂深雪| 久久精品国产亚洲av影院| 国产精品久久久久久久久软件 | 色综合久久久久久久久五月| 久久本道久久综合伊人| 久久精品国产一区| 精品久久久无码中文字幕| 国产成人无码久久久精品一| 7777久久久国产精品消防器材| 亚洲人成无码网站久久99热国产| 国产精品久久婷婷六月丁香| 久久精品亚洲精品国产欧美| 久久精品国产亚洲精品| 国产午夜精品理论片久久| 国产精久久一区二区三区| 久久se这里只有精品| 久久久久久亚洲精品影院| 久久精品www人人爽人人| 精品久久久久久成人AV| 国产精品久久久久久搜索| 99热精品久久只有精品|