• <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.¢% 閱讀(802) 評論(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://www.shnenglu.com/sleepwom/archive/2013/05/19/200390.html?
            我在這篇文章提出的問題, 提供了一種思路.
            久久精品无码一区二区无码| 亚洲精品乱码久久久久久按摩 | 欧美va久久久噜噜噜久久| 色欲久久久天天天综合网 | 久久精品国产秦先生| 热久久国产精品| 久久毛片一区二区| 美女写真久久影院| 三级三级久久三级久久| 国产精品久久久久久久| 久久99九九国产免费看小说| 人人狠狠综合久久亚洲88| 久久久久99这里有精品10| 亚洲国产精品一区二区久久| 午夜精品久久久久| 国产巨作麻豆欧美亚洲综合久久| 亚洲国产精品无码成人片久久| 色综合久久天天综合| 中文字幕热久久久久久久| 欧美午夜精品久久久久久浪潮| 久久精品一本到99热免费| 一本色道久久88综合日韩精品 | 成人a毛片久久免费播放| 久久综合狠狠综合久久综合88| 香蕉久久AⅤ一区二区三区| 国产成人综合久久久久久| 九九99精品久久久久久| 久久成人国产精品免费软件| 久久精品国产亚洲7777| 精品久久久久久国产牛牛app| 国产∨亚洲V天堂无码久久久| 亚洲国产精品高清久久久| 久久久久人妻一区二区三区| 波多野结衣久久精品| 一本大道久久东京热无码AV | MM131亚洲国产美女久久| 久久精品国产亚洲av麻豆色欲 | 欧美日韩久久中文字幕| 无码人妻少妇久久中文字幕| 欧美精品丝袜久久久中文字幕 | 精品国产VA久久久久久久冰|