• <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)論排行榜

            久久久久人妻精品一区三寸蜜桃| 久久国产视频99电影| 中文无码久久精品| 久久综合久久综合久久| 久久国产视频网| 久久精品蜜芽亚洲国产AV| a级毛片无码兔费真人久久| 久久人妻无码中文字幕| 久久久国产精品福利免费| 国产福利电影一区二区三区久久久久成人精品综合 | 久久久久久国产精品免费无码| 热久久这里只有精品| 亚洲中文字幕无码久久精品1| 色综合久久久久网| 久久精品中文闷骚内射| 性做久久久久久久久浪潮| 精品视频久久久久| 青青青伊人色综合久久| 精品蜜臀久久久久99网站| 婷婷久久五月天| 日本精品久久久久影院日本 | 久久久精品久久久久久| 国产成人久久精品区一区二区| 97视频久久久| 狠狠色丁香婷婷久久综合五月| 品成人欧美大片久久国产欧美...| 77777亚洲午夜久久多喷| 久久天天躁狠狠躁夜夜网站| 精品久久久久久中文字幕大豆网| 日韩中文久久| 精品久久久一二三区| 中文字幕精品久久| 久久人人爽人人爽人人片AV麻烦| 久久天天婷婷五月俺也去| 亚洲国产精品无码久久九九| 日韩十八禁一区二区久久| 日本精品一区二区久久久| 无码人妻久久一区二区三区蜜桃| 国产精品久久久香蕉| 波多野结衣AV无码久久一区| 久久久久无码精品国产|