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

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運轉,開心的工作
            簡單、開放、平等的公司文化;尊重個性、自由與個人價值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Protothreads

            Posted on 2013-05-19 15:12 S.l.e!ep.¢% 閱讀(811) 評論(0)  編輯 收藏 引用 所屬分類: C++
            Protothreads是個好東西,
            官網在此 http://www.sics.se/~adam/pt/index.html

            二話不說,上代碼
            #include?"pt.h"?
            #include?
            <stdio.h>
            #include?
            <stdlib.h>

            static??int??countrer;??
            ?
            ??
            PT_THREAD(?example(
            struct??pt??*pt1)?)??
            {??
            ????
            int?i?=?0;
            ????PT_BEGIN(pt1);??

            ????i?
            =?100;
            ????printf(
            "before?i?=?%d\n",?i);

            ????PT_WAIT_UNTIL(pt1,?countrer?
            ==?5?);??
            ????
            ????printf(
            "Threshold?reached\n");??
            ????printf(
            "after?i?=?%d\n",?i);

            ????PT_END(pt1);??
            }??

            int?main(void)??
            {??
            ????
            static??struct??pt??example_pt;?
            ????countrer?
            =?0;??
            ????PT_INIT(
            &example_pt);??
            ????
            ????
            while(1)
            ????{
            ????????
            if(?PT_ENDED?==?example(&example_pt)?)
            ????????????
            break;

            ????????countrer
            ++;??
            ????}

            ????
            return?0;??
            }??

            原理很簡單, 宏展開就是
            #include?<stdio.h>
            #include?
            <stdlib.h>

            #define?PT_WAITING?0
            #define?PT_ENDED?3

            typedef?unsigned?
            short?lc_t;
            struct?pt?
            {
            ????lc_t?lc;
            };

            static??int??countrer;??
            ??
            char?example(struct??pt??*pt1)
            {??
            ????
            int?i?=?0;

            //////////////////////////////////////////////////////////////////////////?begin
            ????{?
            ????????
            switch((pt1)->lc)?
            ????????{?????
            ????????
            case?0:
            //////////////////////////////////////////////////////////////////////////?-begin

            ????????????
            while(1)?
            ????????????{??
            //////////////////////////////////////////////////////////////////////////?call
            ????????????????do?{????????
            ????????????????????(pt1)
            ->lc?=?__LINE__;?case?__LINE__:

            ????????????????????
            if(?!(?countrer?==?5?)?)?
            ????????????????????{
            ????????????????????????
            return?PT_WAITING;????
            ????????????????????}????????????????????????
            ????????????????}?
            while(0);
            //////////////////////////////////////////////////////////////////////////?-call

            ????????????????printf(
            "Threshold?reached\n");??
            ????????????????countrer?
            =?0;??
            ????????????????exit(
            1);
            ????????????}??

            //////////////////////////////////////////////////////////////////////////?end
            ????????}?
            ????????(pt1)
            ->lc?=?0;
            ????????
            return?PT_ENDED;
            ????}
            //////////////////////////////////////////////////////////////////////////?-end
            }

            int?main(void)??
            {??
            ????
            static??struct??pt??example_pt;?
            ????countrer?
            =?0;??

            ????(
            &example_pt)->lc?=?0;
            ????
            ????
            while(1)
            ????{
            ????????example(
            &example_pt);??
            ????????countrer
            ++;??
            ????}

            ????
            return?0;??
            }??

            有個壞處, 寫代碼時
            ?i = 100;????????????????????????????????????? <-----?這里賦了值
            ?printf("before i = %d\n", i);


            到了
            ?printf("Threshold reached\n");?
            ?printf("after i = %d\n", i);????????????? <----- 到了這里你還以為i 是 100? 錯了....

            不過用于解決?
            http://m.shnenglu.com/sleepwom/archive/2013/05/19/200390.html?
            我在這篇文章提出的問題, 提供了一種思路.
            久久国产乱子伦精品免费强| 久久久精品久久久久久| 亚洲综合日韩久久成人AV| 久久不见久久见免费视频7| 伊人热人久久中文字幕| 久久人人爽人人爽人人片AV东京热 | 久久久久四虎国产精品| 欧美伊香蕉久久综合类网站| 中文字幕无码av激情不卡久久| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 97香蕉久久夜色精品国产 | 午夜精品久久久久久| 粉嫩小泬无遮挡久久久久久| 四虎亚洲国产成人久久精品| 国产精品九九九久久九九| 亚洲va久久久噜噜噜久久狠狠 | 久久久久久国产a免费观看黄色大片| 久久er99热精品一区二区| 人妻无码αv中文字幕久久琪琪布| 伊人久久大香线焦综合四虎| 久久国产色AV免费观看| 欧美久久久久久| 久久久久久亚洲精品影院| 青青草国产97免久久费观看| 国产ww久久久久久久久久| 99久久国产免费福利| 久久久中文字幕| www性久久久com| 久久99国产精品久久99| 国产精品久久久久aaaa| 99久久综合狠狠综合久久止| 潮喷大喷水系列无码久久精品| 久久人妻少妇嫩草AV无码专区| 久久香综合精品久久伊人| 久久久久久久女国产乱让韩| 波多野结衣AV无码久久一区| 亚洲中文字幕无码久久2020 | 精品久久久久久国产| 国产精品久久久久一区二区三区| 久久青草国产精品一区| 久久九色综合九色99伊人|