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

            <2011年4月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久99国产一区二区三区| 欧美亚洲日本久久精品| 97久久香蕉国产线看观看| 久久这里有精品| 亚洲成人精品久久| 亚洲国产精品综合久久一线 | 亚洲人成无码www久久久| 国产成人久久精品麻豆一区| 欧美精品丝袜久久久中文字幕 | 久久亚洲熟女cc98cm| 亚洲国产一成人久久精品| 精品综合久久久久久97超人| 久久天堂AV综合合色蜜桃网| 国产精品久久久久无码av| 九九热久久免费视频| segui久久国产精品| 尹人香蕉久久99天天拍| 99久久中文字幕| 久久人人爽人人爽人人片AV高清| 精品久久久久久久久午夜福利| 国产成人无码精品久久久久免费| 精品国产日韩久久亚洲| 色综合久久精品中文字幕首页| 久久夜色精品国产亚洲| 日韩久久无码免费毛片软件| 国产精品久久久久久影院| 无码人妻久久久一区二区三区| 久久久久国产成人精品亚洲午夜| 无码人妻精品一区二区三区久久久 | 久久夜色tv网站| 久久精品国产亚洲AV电影| 四虎国产精品成人免费久久| 久久久精品久久久久特色影视| 成人久久久观看免费毛片| A级毛片无码久久精品免费| 久久婷婷人人澡人人| 久久久久国产精品| 蜜桃麻豆WWW久久囤产精品| 国产精品成人99久久久久 | 久久九九久精品国产| 日本精品久久久久中文字幕|