按老师的例子写的,出现错误

qq_y8hnxvl9 Arduino 多线程编程 最后由 上海小胖 于2017年05月05日回复

  • 1 回答
  • 1.7k 浏览

#include "pt.h"

static struct pt thread1,thread2;

static int flag1,flag2;

void setup() {

  Serial.begin(115200);

  PT_INIT(&thread1);

  PT_INIT(&thread2);

}

static int thread1_entry(struct pt *pt)

{

  PT_BEGIN(pt);

  while (1)

  {

    PT_WAIT_UNTIL(pt,flag1 ! = 0;);

    Serial.println("aaaaa");

    flag1=0;

    flag2=1;

  }

  PT_END(pt);

}

static int thread2_entry(struct pt *pt)

{

  PT_BEGIN(pt);

  while (1)

  {

    flag1=1;

    PT_WAIT_UNTIL(pt, flag2!=0);

    Serial.println("bbbbb");

    flag2=0;

  }

  PT_END(pt);

}

void loop() {

  thread1_entry(&thread1);

  thread2_entry(&thread2);

}

错误提示如下:

Arduino:1.7.10 (Windows 7), 板:"Arduino Uno"

In file included from sketch_feb14a.ino:2:0:

sketch_feb14a.ino: In function 'int thread1_entry(pt*)':

sketch_feb14a.ino:15:28: error: expected ')' before '!' token

D:Program Files (x86)ArduinolibrariesProtoThreads/pt.h:162:10: note: in definition of macro 'PT_WAIT_UNTIL'

     if(!(condition)) {    

          ^

sketch_feb14a.ino:15:33: error: expected ')' before ';' token

D:Program Files (x86)ArduinolibrariesProtoThreads/pt.h:162:10: note: in definition of macro 'PT_WAIT_UNTIL'

     if(!(condition)) {    

          ^

D:Program Files (x86)ArduinolibrariesProtoThreads/pt.h:162:19: error: expected primary-expression before ')' token

     if(!(condition)) {    

                   ^

sketch_feb14a.ino:15:5: note: in expansion of macro 'PT_WAIT_UNTIL'

D:Program Files (x86)ArduinolibrariesProtoThreads/pt.h:162:19: error: expected ';' before ')' token

     if(!(condition)) {    

                   ^

sketch_feb14a.ino:15:5: note: in expansion of macro 'PT_WAIT_UNTIL'

编译有误。

  • 上海小胖 2017年05月05日 回答 #1楼
  • if(!(condition)) {    

    报错提示很明显,condition不需要括号

  • 0 评论