hiroyuki-sato / ucx

Unified Communication X (mailing list - https://elist.ornl.gov/mailman/listinfo/ucx-group):
http://www.openucx.org
Other
2 stars 0 forks source link

GCD memo #26

Open hiroyuki-sato opened 4 years ago

hiroyuki-sato commented 4 years ago
#include <dispatch/dispatch.h>
#include <stdio.h>

void func(){
  dispatch_queue_t queue = dispatch_queue_create("org.openucx",
                                               DISPATCH_QUEUE_CONCURRENT);
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), queue, ^{
    printf("called 3sec after\n");
  });
  sleep(3);
  printf("call this part first\n");
  dispatch_release(queue);
}

int main(){
  int i;
  func();

  for(i=0; i<5;i++){ printf("%d\n",i); sleep(1); }

}

GCD (Grand Central Dispatch) - Dispatch Queue でマルチスレッドプログラミング