Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-7464

[C++] Refine CpuInfo singleton with std::call_once

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.16.0
    • Component/s: C++
    • Flags:
      Patch

      Description

      CpuInfo singleton is created and initialized on first invocation of
      CpuInfo::GetInstance(). All calls afterwards return reference to the
      same instance. Current code uses std::mutex to make sure that CpuInfo
      is created only once, but it introduces unnecessary overhead for later
      calls. Concurrent threads getting the created instance should not block
      each other.

      Replace std::mutex with std::call_once to fix this issue.

      References:
      [1] https://en.cppreference.com/w/cpp/thread/call_once
      [2] http://www.modernescpp.com/index.php/thread-safe-initialization-of-data

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                yibo Yibo Cai
                Reporter:
                yibo Yibo Cai
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m