Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1247
diff -u -p -r1.1247 common.inc
--- includes/common.inc	28 Oct 2010 02:00:27 -0000	1.1247
+++ includes/common.inc	29 Oct 2010 03:16:31 -0000
@@ -5573,7 +5574,14 @@ function drupal_render_cache_get($elemen
   }
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
 
-  if (!empty($cid) && $cache = cache_get($cid, $bin)) {
+  if (!$cache = cache_get($cid, $bin) && !lock_acquire($cid)) {
+    lock_wait($cid);
+    if (!$cache = cache_get($cid, $bin)) {
+      lock_acquire($cid);
+    }
+  }
+
+  if ($cache) {
     // Add additional libraries, JavaScript, CSS and other data attached
     // to this element.
     if (isset($cache->data['#attached'])) {
@@ -5618,6 +5630,7 @@ function drupal_render_cache_set(&$marku
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
   $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CACHE_PERMANENT;
   cache_set($cid, $data, $bin, $expire);
+  lock_release($cid);
 }
 
 /**
