diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 111e89a..0026cb0 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -296,12 +296,12 @@ abstract class DrupalCacheArray implements ArrayAccess {
   /**
    * A cid to pass to cache()->set() and cache()->get().
    */
-  private $cid;
+  protected $cid;
 
   /**
    * A bin to pass to cache()->set() and cache()->get().
    */
-  private $bin;
+  protected $bin;
 
   /**
    * An array of keys to add to the cache at the end of the request.
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 3d19d3e..cf78fe1 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -2336,7 +2336,7 @@ function l($text, $path, array $options = array()) {
     // rendering.
     if (variable_get('theme_link', TRUE)) {
       drupal_theme_initialize();
-      $registry = theme_get_registry();
+      $registry = theme_get_registry(FALSE);
       // We don't want to duplicate functionality that's in theme(), so any
       // hint of a module or theme doing anything at all special with the 'link'
       // theme hook should simply result in theme() being called. This includes
diff --git a/core/modules/simpletest/tests/theme.test b/core/modules/simpletest/tests/theme.test
index b47e379..2e18b73 100644
--- a/core/modules/simpletest/tests/theme.test
+++ b/core/modules/simpletest/tests/theme.test
@@ -540,3 +540,56 @@ class ThemeHtmlTplPhpAttributesTestCase extends DrupalWebTestCase {
     $this->assertTrue(count($attributes) == 1, t('Attribute set in the body element via hook_preprocess_html() found.'));
   }
 }
+
+/**
+ * Tests for the ThemeRegistry class.
+ */
+class ThemeRegistryTestCase extends DrupalWebTestCase {
+  protected $profile = 'testing';
+  public static function getInfo() {
+    return array(
+      'name' => 'ThemeRegistry',
+      'description' => 'Tests the behaviour of the ThemeRegistry class',
+      'group' => 'Theme',
+    );
+  }
+  function setUp() {
+    parent::setUp('theme_test');
+  }
+
+  /**
+   * Test the behaviour of the theme registry class.
+   */
+  function testRaceCondition() {
+    $_SERVER['REQUEST_METHOD'] = 'GET';
+    $cid = 'test_theme_registry';
+
+    // Directly instantiate the theme registry, this will cause a base cache
+    // entry to be written in __construct().
+    $registry = new ThemeRegistry($cid, 'cache');
+
+    // Confirm the cache entry was written.
+    $this->assertTrue(cache()->get($cid));
+
+    // Trigger a cache miss for an offset.
+    $this->assertTrue($registry['theme_test_template_test']);
+    // This will cause the ThemeRegistry class to write an updated version of
+    // the cache entry when it is destroyed, usually at the end of the request.
+    // Before that happens, manually delete the cache entry we created earlier
+    // so that the new entry is written from scratch.
+    cache()->delete($cid);
+
+    // Destroy the class so that it triggers a cache write for the offset.
+    unset($registry);
+
+    // Confirm a cache entry was written.
+    $this->assertTrue(cache()->get($cid));
+
+    // Create a new instance of the class. Confirm that both the offset
+    // requested previously, and one that has not yet been requested are both
+    // available.
+    $registry = new ThemeRegistry($cid, 'cache');
+    $this->assertTrue($registry['theme_test_template_test']);
+    $this->assertTrue($registry['theme_test_template_test_2']);
+  }
+}
diff --git a/core/modules/simpletest/tests/theme_test.module b/core/modules/simpletest/tests/theme_test.module
index 400902d..8c45e82 100644
--- a/core/modules/simpletest/tests/theme_test.module
+++ b/core/modules/simpletest/tests/theme_test.module
@@ -7,6 +7,9 @@ function theme_test_theme($existing, $type, $theme, $path) {
   $items['theme_test_template_test'] = array(
     'template' => 'theme_test.template_test',
   );
+  $items['theme_test_template_test_2'] = array(
+    'template' => 'theme_test.template_test',
+  );
 
   return $items;
 }
