[all-commits] [llvm/llvm-project] b923c1: [libomptarget] Fix a race condition in checkDevice...

lechenyu via All-commits all-commits at lists.llvm.org
Mon Oct 31 07:38:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b923c15d3c00c78a7b9258e79755df9587e1f0b1
      https://github.com/llvm/llvm-project/commit/b923c15d3c00c78a7b9258e79755df9587e1f0b1
  Author: Lechen Yu <lechenyu21 at gmail.com>
  Date:   2022-10-31 (Mon, 31 Oct 2022)

  Changed paths:
    M openmp/libomptarget/src/omptarget.cpp

  Log Message:
  -----------
  [libomptarget] Fix a race condition in checkDeviceAndCtors

When multiple threads invoke checkDeviceAndCtors, both of them may read true
from the shared variable Device.HasPendingGlobals, and then invoke initLibrary
redundantly. Therefore only protecting the access to Device.HasPendingGlobals
is not sufficient to guarantee that initLibrary is invoked just once.

To fix this race condition, we move the invocation of initLibrary into the
critical section, and remove the same lock inside initLibrary.

Differential Revision: https://reviews.llvm.org/D136952




More information about the All-commits mailing list