• <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.¢%

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

            Protothreads

            Posted on 2013-05-19 15:12 S.l.e!ep.¢% 閱讀(809) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++
            Protothreads是個(gè)好東西,
            官網(wǎng)在此 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;??
            }??

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


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

            不過用于解決?
            http://www.shnenglu.com/sleepwom/archive/2013/05/19/200390.html?
            我在這篇文章提出的問題, 提供了一種思路.
            久久91这里精品国产2020| 伊人久久大香线蕉综合Av| 国内精品综合久久久40p| 久久中文精品无码中文字幕| 免费一级欧美大片久久网| 久久久久国色AV免费观看| 久久午夜福利电影| 久久综合久久美利坚合众国| 久久狠狠高潮亚洲精品| 精品无码人妻久久久久久| 亚洲国产成人久久综合区| 韩国免费A级毛片久久| 国内精品久久久久影院网站| 深夜久久AAAAA级毛片免费看| 欧美va久久久噜噜噜久久| 久久精品亚洲福利| 国产成人久久精品一区二区三区| 久久人人爽人人爽人人片av高请| 久久99精品免费一区二区| 久久人人爽人人爽人人片AV高清 | 久久久久久久久无码精品亚洲日韩 | a高清免费毛片久久| 久久福利资源国产精品999| 97久久国产亚洲精品超碰热| 要久久爱在线免费观看| 国产精品美女久久久网AV| 久久精品天天中文字幕人妻| 青青草国产97免久久费观看| 99久久国产综合精品网成人影院| 久久久亚洲欧洲日产国码二区| 久久婷婷色综合一区二区| 久久综合狠狠色综合伊人| 国产激情久久久久影院老熟女免费| 伊人久久综合无码成人网| 欧美亚洲国产精品久久高清| 久久无码AV中文出轨人妻| 久久精品国产福利国产琪琪| 久久精品无码一区二区日韩AV| 老司机午夜网站国内精品久久久久久久久 | 少妇人妻综合久久中文字幕| 亚洲午夜精品久久久久久app|