hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Haohui Mai (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HADOOP-10487) Racy code in UserGroupInformation#ensureInitialized()
Date Thu, 10 Apr 2014 00:55:18 GMT
Haohui Mai created HADOOP-10487:
-----------------------------------

             Summary: Racy code in UserGroupInformation#ensureInitialized()
                 Key: HADOOP-10487
                 URL: https://issues.apache.org/jira/browse/HADOOP-10487
             Project: Hadoop Common
          Issue Type: Bug
            Reporter: Haohui Mai
            Assignee: Haohui Mai


UserGroupInformation#ensureInitialized() uses the double-check-locking pattern to reduce the
synchronization cost:

{code}
  private static void ensureInitialized() {
    if (conf == null) {
      synchronized(UserGroupInformation.class) {
        if (conf == null) { // someone might have beat us
          initialize(new Configuration(), false);
        }
      }
    }
  }
{code}

As [~tlipcon] pointed out in the original jira (HADOOP-9748). This pattern is incorrect. Please
see more details in http://en.wikipedia.org/wiki/Double-checked_locking and http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

This jira proposes to use the static class holder pattern to do it correctly.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message