Solve the race condition described in the bug 872558 report which can
result in:
- thread crashing trying to remove semaphore from dict
- two threads getting different semaphores for the same name
First case is solved automatically by weakref dictionary. No explicit
deletion takes place.
The second case is solved by getting existing or new semaphore in one
step. Once a local reference to the semaphore is obtained, it can be
safely assigned to the dictionary if it's missing. If it's present, it
will not be removed anymore because there's at least one strong
reference present (local variable 'sem').
Reviewed: https:/ /review. openstack. org/10924 github. com/openstack/ nova/commit/ 9206ee5a63a65e0 76342896e3b41bb cbf819af56
Committed: http://
Submitter: Jenkins
Branch: master
commit 9206ee5a63a65e0 76342896e3b41bb cbf819af56
Author: Stanislaw Pitucha <email address hidden>
Date: Mon Aug 6 23:16:07 2012 +0100
Solve possible race in semaphor creation
Solve the race condition described in the bug 872558 report which can
result in:
- thread crashing trying to remove semaphore from dict
- two threads getting different semaphores for the same name
First case is solved automatically by weakref dictionary. No explicit
deletion takes place.
The second case is solved by getting existing or new semaphore in one
step. Once a local reference to the semaphore is obtained, it can be
safely assigned to the dictionary if it's missing. If it's present, it
will not be removed anymore because there's at least one strong
reference present (local variable 'sem').
This solution is only valid for greenthreads.
Change-Id: I6bddc3e7abb39f d75e1f03abb2ea0 f911b761957