Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
titleUsing the IN clause
linenumberstrue
#include <stdio.h>
int main (int argc, char ** argv) {
  int i = 0;
  finish {
    for(i=0; i < LG; ) {
      async IN(i) { // 'i' passed by copy
        printf("Hello %d times !\n", i);
      i--; // decr copy of 'i', only visible in the async body
    }
 
      }
      i++; // incr originalloop's 'i'
 in the spawn scope}
  }
  return 0;
}

This example shows how to create a bunch of async in a loop. The loop index 'i' is passed as an IN argument so that its value is available in the async's body.