• <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++并發(fā)和并行 concurrency & parallelism

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久香蕉国产线看观看猫咪?v| 国产精品99久久久精品无码| 996久久国产精品线观看| 日韩精品久久久久久免费| 欧洲成人午夜精品无码区久久| 久久精品国产亚洲沈樵| 久久久久久青草大香综合精品| 偷偷做久久久久网站| 久久国产精品99国产精| 久久久这里有精品中文字幕| 亚洲精品无码久久久久| 久久99精品久久久久久噜噜| 久久久久久综合网天天| 国产精品亚洲综合专区片高清久久久| 久久人人爽人人爽人人片AV不 | 囯产极品美女高潮无套久久久| 久久精品www人人爽人人| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 色综合久久88色综合天天| 欧美久久一区二区三区| 日本精品久久久久中文字幕| 99久久99久久精品国产片果冻 | 亚洲国产精品无码久久青草| 精品国产一区二区三区久久久狼| 亚洲Av无码国产情品久久| 国产精品成人精品久久久| 精品国产乱码久久久久久1区2区| 一本一道久久a久久精品综合| 精品久久久久一区二区三区| 国内精品久久久久久久97牛牛 | 99久久人人爽亚洲精品美女| 99久久国产热无码精品免费 | 99久久免费国产特黄| 久久99国内精品自在现线| 奇米综合四色77777久久| 久久久SS麻豆欧美国产日韩| 久久综合精品国产一区二区三区| 66精品综合久久久久久久| 亚洲成人精品久久| 久久精品成人免费国产片小草| 91精品国产91久久|