Uploaded image for project: 'HPCC'
  1. HPCC
  2. HPCC-17522

Create a template helper function for correctly implementing singletons

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.4.0
    • Component/s: JLib
    • Labels:
      None

      Description

      Currently there are quite a few functions like this one:

      inline CKeyStore *queryKeyStore()
      {
          if (keyStore) return keyStore; // avoid crit
          CriticalBlock b(*initCrit);
          if (!keyStore) keyStore = new CKeyStore;
          return keyStore;
      }
      

      which are technically incorrect - the compiler is at perfect liberty to reuse the value of keyStore from before the CriticalBlock inside the CriticalBlock - causing two CKeyStores to be created.

      It would be better if there was a single helper function to safely implement this pattern (similar to std::call_once).

        Attachments

          Activity

            People

            • Assignee:
              ghalliday Gavin Halliday
              Reporter:
              ghalliday Gavin Halliday
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: