• <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://www.shnenglu.com/sleepwom/archive/2013/05/19/200390.html?
            我在這篇文章提出的問題, 提供了一種思路.
            一本色道久久88—综合亚洲精品| 欧美一区二区三区久久综合| 99久久精品国产高清一区二区 | 久久99热这里只频精品6| 99精品久久精品一区二区| 伊人久久综合无码成人网| www亚洲欲色成人久久精品| 精品国产乱码久久久久软件| 国产精品成人无码久久久久久| 午夜精品久久久久| 久久国产精品免费一区二区三区| 99蜜桃臀久久久欧美精品网站| 国产69精品久久久久99| 97久久香蕉国产线看观看| 国内精品伊人久久久影院| 草草久久久无码国产专区| 久久精品国产亚洲AV电影 | 99蜜桃臀久久久欧美精品网站 | 久久久久久无码国产精品中文字幕| 久久久久亚洲精品日久生情| 国产日韩久久久精品影院首页| 亚洲日本va中文字幕久久| 国产精品乱码久久久久久软件| 久久精品国产第一区二区| 99久久精品免费看国产一区二区三区 | 久久99精品国产麻豆宅宅| 久久精品国产久精国产思思| 一本一本久久A久久综合精品| 亚洲国产成人乱码精品女人久久久不卡| 99久久人妻无码精品系列蜜桃| 久久婷婷国产剧情内射白浆 | 国产精品VIDEOSSEX久久发布| 国产精品99久久99久久久| 久久国产亚洲精品无码| 国产精品久久国产精麻豆99网站| 久久精品天天中文字幕人妻 | 日韩欧美亚洲综合久久影院Ds | 国产精品VIDEOSSEX久久发布| 九九久久精品无码专区| 久久亚洲国产精品123区| 久久中文字幕视频、最近更新 |