Skip to content

Commit 65ce4f1

Browse files
committed
Update deliveries value atomically to avoid potential race condition
1 parent e2d5eb5 commit 65ce4f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/dispatch_read2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,15 @@ test_writes_reads_eagain(void) // rdar://problem/8333366
348348

349349
dispatch_queue_t q = dispatch_get_global_queue(0,0);
350350
dispatch_group_t g = dispatch_group_create();
351-
__block size_t siz_acc = 0, deliveries = 0;
351+
volatile __block size_t deliveries = 0;
352+
__block size_t siz_acc = 0;
352353
__block void (^b)(dispatch_data_t, int);
353354
b = Block_copy(^(dispatch_data_t data, int err) {
354355
if (err) {
355356
test_errno("dispatch_read", err, 0);
356357
test_stop();
357358
}
358-
deliveries++;
359+
OSAtomicIncrement32(&deliveries);
359360
siz_acc += dispatch_data_get_size(data);
360361
if (siz_acc < siz) {
361362
dispatch_group_enter(g);

0 commit comments

Comments
 (0)