cpython: 0d4ca1e77205 (original) (raw)

Mercurial > cpython

changeset 71126:0d4ca1e77205 3.1

Issue #12352: Fix a deadlock in multiprocessing.Heap when a block is freed by the garbage collector while the Heap lock is held. [#12352]

Charles-François Natali neologix@free.fr
date Sat, 02 Jul 2011 14:35:49 +0200
parents 633597815463
children 37606505b227 42ec507815d2
files Lib/multiprocessing/heap.py Lib/test/test_multiprocessing.py Misc/NEWS
diffstat 3 files changed, 60 insertions(+), 6 deletions(-)[+] [-] Lib/multiprocessing/heap.py 39 Lib/test/test_multiprocessing.py 24 Misc/NEWS 3

line wrap: on

line diff

--- a/Lib/multiprocessing/heap.py +++ b/Lib/multiprocessing/heap.py @@ -101,6 +101,8 @@ class Heap(object): self._stop_to_block = {} self._allocated_blocks = set() self._arenas = []

@staticmethod def _roundup(n, alignment): @@ -175,15 +177,39 @@ class Heap(object): return start, stop

+ def free(self, block): # free a block returned by malloc()

def malloc(self, size): # return a block of right size (possibly rounded up) @@ -191,6 +217,7 @@ class Heap(object): if os.getpid() != self._lastpid: self.init() # reinitialize after fork self._lock.acquire()

--- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1580,6 +1580,8 @@ class _TestHeap(BaseTestCase): # verify the state of the heap all = [] occupied = 0

@@ -1597,6 +1599,28 @@ class _TestHeap(BaseTestCase): self.assertTrue((arena != narena and nstart == 0) or (stop == nstart))

+

+ # # #

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Core and Builtins Library ------- +- Issue #12352: Fix a deadlock in multiprocessing.Heap when a block is freed by