brintos

brintos / llvm-project-archived public Read only

0
0
Text · 765 B · 9e4a3ea Raw
41 lines · c
1// Check that we don't crash when dispatch_main calls pthread_exit which2// quits the main thread.3 4// RUN: %clang_tsan %s -o %t5// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'6 7#include <dispatch/dispatch.h>8 9#include <stdio.h>10#include <stdlib.h>11 12int main() {13  fprintf(stderr,"Hello world");14 15  dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);16 17  dispatch_async(q, ^{18    fprintf(stderr,"1");19  });20 21  dispatch_async(q, ^{22    fprintf(stderr,"2");23  });24 25  dispatch_async(q, ^{26    fprintf(stderr,"3");27 28    dispatch_async(dispatch_get_main_queue(), ^{29      fprintf(stderr,"Done.");30      sleep(1);31      exit(0);32    });33  });34 35  dispatch_main();36}37 38// CHECK: Hello world39// CHECK: 12340// CHECK: Done.41