]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dlopen-race.dtest/main.c
dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-race.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.c -o $BUILD_DIR/dlopen-race.exe -DRUN_DIR="$RUN_DIR"
4
5 // RUN: ./dlopen-race.exe
6
7 #include <stdio.h>
8 #include <dlfcn.h>
9 #include <stdlib.h>
10 #include <dispatch/dispatch.h>
11
12
13
14 int main()
15 {
16 printf("[BEGIN] dlopen-read\n");
17
18 __block bool allGood = true;
19 dispatch_apply(6, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t index) {
20 for (int i=0; i < 500; ++i) {
21 void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
22 if ( handle == NULL ) {
23 printf("[FAIL] dlopen-read: %s\n", dlerror());
24 exit(0);
25 }
26 dlclose(handle);
27 }
28 });
29
30 printf("[PASS] dlopen-read\n");
31 return 0;
32 }
33