cpython: Handle a possible race condition
http://hg.python.org/cpython/rev/b3aeaef6c315 changeset: 76675:b3aeaef6c315 user: Raymond Hettinger <python@rcn.com> date: Mon Apr 30 14:14:28 2012 -0700 summary: Handle a possible race condition files: Lib/functools.py | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py --- a/Lib/functools.py +++ b/Lib/functools.py @@ -241,6 +241,12 @@ return result result = user_function(*args, **kwds) with lock: + if key in cache: + # getting here means that this same key was added to the + # cache while the lock was released. since the link + # update is already done, we need only return the + # computed result and update the count of misses. + pass if currsize < maxsize: # put result in a new link at the front of the queue last = root[PREV] -- Repository URL: http://hg.python.org/cpython
On Tue, May 1, 2012 at 10:35 AM, raymond.hettinger <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/b3aeaef6c315 changeset: 76675:b3aeaef6c315 user: Raymond Hettinger <python@rcn.com> date: Mon Apr 30 14:14:28 2012 -0700 summary: Handle a possible race condition
files: Lib/functools.py | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/Lib/functools.py b/Lib/functools.py --- a/Lib/functools.py +++ b/Lib/functools.py @@ -241,6 +241,12 @@ return result result = user_function(*args, **kwds) with lock: + if key in cache: + # getting here means that this same key was added to the + # cache while the lock was released. since the link + # update is already done, we need only return the + # computed result and update the count of misses. + pass if currsize < maxsize: # put result in a new link at the front of the queue last = root[PREV]
To get the desired effect, I believe you also need s/if currsize/elif currsize/ Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (2)
-
Nick Coghlan -
raymond.hettinger