heliosproj / HeliOS

A community delivered, open source embedded operating system project.
http://www.heliosproj.org
GNU General Public License v2.0
352 stars 42 forks source link

Coop does now work on UNO #10

Closed kwrtz closed 3 years ago

kwrtz commented 3 years ago

I get follwowing result on UNO:

ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL

while using following code:

`/*

/*

/*

/*

void taskShortB(int32t id) { float a = 0.0f;

for (int32_t i = 0; i < 10000; i++) a *= 3.14f;

Serial.print("B"); }

void taskShortC(int32t id) { float a = 0.0f;

for (int32_t i = 0; i < 40000; i++) a *= 3.14f;

Serial.print("C"); }

/*

void setup() { /*

void loop() { /*

ThomasHornschuh commented 3 years ago

Your loop code will most likey optimized away bei GCC: Because a is never used, it does not need to be calculated. Even if you try to use a (e.g. printing it after the loop), the compiler will notice that it is essentially a constant expression (0*3.14) and will calculate this at the compile time and will essentially condense your loop to something like printf("%f\n",0) Do ensure that your loop is not optimized away you should

To be sure that your code is not optimized away use the gnu objdump utility objdump -d <elffile> and check the generated assembler code.

BTW: You tried to markup your code but to do it right you need three back ticks instead of one. Check with the preview function if your markup works as intended before posting. For longer code pieces you can also create a github gist (gist.github.com) and just store here

kwrtz commented 3 years ago

Ok, thank you very much. I didn't thought about the optimisation. Now it works :)

MannyPeterson commented 3 years ago

@kwrtz I will fix the Coop example Arduino sketch in this release. I don't want other's to get confused by the optimizations GCC is performing behind the scenes. I will fix the code as @ThomasHornschuh suggested. Thank you.

MannyPeterson commented 3 years ago

Sorry for re-opening again. I will fix the example Arduino sketch as shown below. Thanks.

void taskShortA(int id_) {
  volatile float a = 0.0f, b = 0.0f;

  for (int32_t i = 0; i < 10000; i++)
    a += i;

  b = a;

  Serial.print("A");
}