Skip to content

Update deliveries value atomically to avoid potential race condition #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/dispatch_read2.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,20 @@ test_writes_reads_eagain(void) // rdar://problem/8333366
test_errno("pipe", errno, 0);
test_stop();
}
const size_t chunks = 320;
const int32_t chunks = 320;
const size_t siz_chunk = 32, siz = siz_chunk * chunks;

dispatch_queue_t q = dispatch_get_global_queue(0,0);
dispatch_group_t g = dispatch_group_create();
__block size_t siz_acc = 0, deliveries = 0;
volatile __block int32_t deliveries = 0;
__block size_t siz_acc = 0;
__block void (^b)(dispatch_data_t, int);
b = Block_copy(^(dispatch_data_t data, int err) {
if (err) {
test_errno("dispatch_read", err, 0);
test_stop();
}
deliveries++;
OSAtomicIncrement32(&deliveries);
siz_acc += dispatch_data_get_size(data);
if (siz_acc < siz) {
dispatch_group_enter(g);
Expand Down Expand Up @@ -383,7 +384,7 @@ test_writes_reads_eagain(void) // rdar://problem/8333366
close(in);
close(*(fd+1));
test_group_wait(g);
test_long("dispatch_read deliveries", deliveries, chunks);
test_int32("dispatch_read deliveries", deliveries, chunks);
test_long("dispatch_read data size", siz_acc, siz);
close(*fd);
Block_release(b);
Expand Down