3
3
// RUN: %clang_tsan %s -o %t
4
4
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
5
5
6
- // REQUIRES: rdar57365733
7
-
8
6
#include <mach/mach.h>
9
7
#include <mach/mach_vm.h>
10
8
#include <pthread.h>
@@ -31,9 +29,11 @@ static int *alloc() {
31
29
32
30
static void alloc_fixed (int * ptr ) {
33
31
mach_vm_address_t addr = (mach_vm_address_t )ptr ;
34
- kern_return_t res =
35
- mach_vm_allocate (mach_task_self (), & addr , alloc_size , VM_FLAGS_FIXED );
36
- assert (res == KERN_SUCCESS );
32
+ kern_return_t res ;
33
+ // Re-allocation via VM_FLAGS_FIXED sporadically fails.
34
+ do {
35
+ res = mach_vm_allocate (mach_task_self (), & addr , alloc_size , VM_FLAGS_FIXED );
36
+ } while (res != KERN_SUCCESS );
37
37
}
38
38
39
39
static void dealloc (int * ptr ) {
@@ -46,8 +46,9 @@ static void *Thread(void *arg) {
46
46
* global_ptr = 7 ; // Assignment 1
47
47
48
48
// We want to test that TSan does not report a race between the two
49
- // assignments to global_ptr when memory is re-allocated here. The calls to
50
- // the API itself are racy though, so ignore them.
49
+ // assignments to *global_ptr when the underlying memory is re-allocated
50
+ // between assignments. The calls to the API itself are racy though, so ignore
51
+ // them.
51
52
AnnotateIgnoreWritesBegin (__FILE__ , __LINE__ );
52
53
dealloc (global_ptr );
53
54
alloc_fixed (global_ptr );
0 commit comments