[Openmp-commits] [PATCH] D81804: [OpenMP][Tests] fix data race in a OpenMP runtime test

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sun Jun 14 06:56:47 PDT 2020


protze.joachim created this revision.
protze.joachim added a reviewer: AndreyChurbanov.
protze.joachim added a project: OpenMP.
Herald added subscribers: sstefan1, jfb, guansong, yaxunl.
Herald added a reviewer: jdoerfert.

Aggressive optimization might translate

  while(block);

to

  while(tid!=0);

The atomic read/write adds the necessary flushes, so that the worker threads will finally see the update.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81804

Files:
  openmp/runtime/test/tasking/omp_fill_taskqueue.c


Index: openmp/runtime/test/tasking/omp_fill_taskqueue.c
===================================================================
--- openmp/runtime/test/tasking/omp_fill_taskqueue.c
+++ openmp/runtime/test/tasking/omp_fill_taskqueue.c
@@ -47,10 +47,14 @@
           // all tasks, and detect the test failure if it has not been done yet.
           if (failed < 0)
             failed = throttling ? enqueued == NUM_TASKS : enqueued < NUM_TASKS;
+#pragma omp atomic write
           block = 0;
         }
-        while (block)
-          ;
+        int wait = 0;
+        do {
+#pragma omp atomic read
+          wait = block;
+        } while (wait);
       }
     }
     block = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81804.270617.patch
Type: text/x-patch
Size: 679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200614/50fd6772/attachment.bin>


More information about the Openmp-commits mailing list