1// RUN: %clang_tsan %s -o %t
2// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
3
4#include <dispatch/dispatch.h>
5
6#include <stdio.h>
7
8void notify_callback(void *context) {
9 // Do nothing.
10}
11
12int main() {
13 fprintf(stderr, format: "Hello world.");
14
15 dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
16
17 for (int i = 0; i < 300000; i++) {
18 dispatch_group_t g = dispatch_group_create();
19 dispatch_group_enter(g);
20 dispatch_async(q, ^{
21 dispatch_group_leave(g);
22 });
23 dispatch_group_notify(g, q, ^{
24 // Do nothing.
25 });
26 dispatch_release(g);
27 }
28
29 for (int i = 0; i < 300000; i++) {
30 dispatch_group_t g = dispatch_group_create();
31 dispatch_group_enter(g);
32 dispatch_async(q, ^{
33 dispatch_group_leave(g);
34 });
35 dispatch_group_notify_f(g, q, NULL, &notify_callback);
36 dispatch_release(g);
37 }
38
39 fprintf(stderr, format: "Done.");
40}
41
42// CHECK: Hello world.
43// CHECK: Done.
44

source code of compiler-rt/test/tsan/libdispatch/groups-stress.c