Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Unified Diff: Lib/multiprocessing/heap.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/multiprocessing/connection.py ('k') | Lib/multiprocessing/process.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/multiprocessing/heap.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/multiprocessing/heap.py Mon Jul 25 09:47:18 2011 -0400
@@ -101,8 +101,6 @@
self._stop_to_block = {}
self._allocated_blocks = set()
self._arenas = []
- # list of pending blocks to free - see free() comment below
- self._pending_free_blocks = []
@staticmethod
def _roundup(n, alignment):
@@ -177,39 +175,15 @@
return start, stop
- def _free_pending_blocks(self):
- # Free all the blocks in the pending list - called with the lock held.
- while True:
- try:
- block = self._pending_free_blocks.pop()
- except IndexError:
- break
+ def free(self, block):
+ # free a block returned by malloc()
+ assert os.getpid() == self._lastpid
+ self._lock.acquire()
+ try:
self._allocated_blocks.remove(block)
self._free(block)
-
- def free(self, block):
- # free a block returned by malloc()
- # Since free() can be called asynchronously by the GC, it could happen
- # that it's called while self._lock is held: in that case,
- # self._lock.acquire() would deadlock (issue #12352). To avoid that, a
- # trylock is used instead, and if the lock can't be acquired
- # immediately, the block is added to a list of blocks to be freed
- # synchronously sometimes later from malloc() or free(), by calling
- # _free_pending_blocks() (appending and retrieving from a list is not
- # strictly thread-safe but under cPython it's atomic thanks to the GIL).
- assert os.getpid() == self._lastpid
- if not self._lock.acquire(False):
- # can't acquire the lock right now, add the block to the list of
- # pending blocks to free
- self._pending_free_blocks.append(block)
- else:
- # we hold the lock
- try:
- self._free_pending_blocks()
- self._allocated_blocks.remove(block)
- self._free(block)
- finally:
- self._lock.release()
+ finally:
+ self._lock.release()
def malloc(self, size):
# return a block of right size (possibly rounded up)
@@ -217,7 +191,6 @@
if os.getpid() != self._lastpid:
self.__init__() # reinitialize after fork
self._lock.acquire()
- self._free_pending_blocks()
try:
size = self._roundup(max(size,1), self._alignment)
(arena, start, stop) = self._malloc(size)
« no previous file with comments | « Lib/multiprocessing/connection.py ('k') | Lib/multiprocessing/process.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+