dongjoon-hyun commented on a change in pull request #23272: [SPARK-26265][Core] 
Fix deadlock in BytesToBytesMap.MapIterator when locking both 
BytesToBytesMap.MapIterator and TaskMemoryManager
URL: https://github.com/apache/spark/pull/23272#discussion_r240465896
 
 

 ##########
 File path: 
core/src/test/java/org/apache/spark/unsafe/map/AbstractBytesToBytesMapSuite.java
 ##########
 @@ -667,4 +669,54 @@ public void testPeakMemoryUsed() {
     }
   }
 
+  @Test
+  public void avoidDeadlock() throws InterruptedException {
+    memoryManager.limit(PAGE_SIZE_BYTES);
+    MemoryMode mode = useOffHeapMemoryAllocator() ? MemoryMode.OFF_HEAP: 
MemoryMode.ON_HEAP;
+    TestMemoryConsumer c1 = new TestMemoryConsumer(taskMemoryManager, mode);
+    BytesToBytesMap map =
+      new BytesToBytesMap(taskMemoryManager, blockManager, serializerManager, 
1, 0.5, 1024);
+
+    Runnable memoryConsumer = new Runnable() {
+      @Override
+      public void run() {
+        int i = 0;
+        long used = 0;
+        while (i < 10) {
+          c1.use(10000000);
+          used += 10000000;
+          i++;
+        }
+        c1.free(used);
+      }
+    };
+
+    Thread thread = new Thread(memoryConsumer);
+
+    try {
+      int i;
+      for (i = 0; i < 1024; i++) {
 
 Review comment:
   Let's use `for (int i = 0; ...` here and line 708 because `int i` is not 
referenced outside of `for` loop.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to