dyld-750.5.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 #include "test_support.h"
13
14 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
15 __block bool allGood = true;
16 dispatch_apply(6, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t index) {
17 for (int i=0; i < 500; ++i) {
18 void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
19 if ( handle == NULL ) {
20 FAIL("dlopen-read: %s", dlerror());
21 }
22 dlclose(handle);
23 }
24 });
25
26 PASS("Success");
27 return 0;
28 }
29