This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Fix synchronization in dispatch_sync
ClosedPublic

Authored by kubamracek on Mar 27 2016, 2:07 PM.

Details

Summary

In the interceptor for dispatch_sync, we're currently missing synchronization between the callback and the code *after* the call to dispatch_sync. So we'll false report a race in:

// now executing on a background queue/thread
dispatch_sync(main_queue, ^{ // "main_queue" forces the callback to be executed on a different thread
  x = 42;
});
print(x); // back on the background_thread

This patch fixes this by adding an extra release+acquire pair to dispatch_sync() and similar APIs. Added a testcase.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek updated this revision to Diff 51748.Mar 27 2016, 2:07 PM
kubamracek retitled this revision from to [tsan] Fix synchronization in dispatch_sync.
kubamracek updated this object.
kubamracek added reviewers: dvyukov, glider, samsonov, kcc.
dvyukov accepted this revision.Apr 4 2016, 4:03 AM
dvyukov edited edge metadata.
This revision is now accepted and ready to land.Apr 4 2016, 4:03 AM
This revision was automatically updated to reflect the committed changes.