mutex? protecting global data/critical section
Brian Alexander
brian094 at sympatico.ca
Fri Sep 19 15:10:09 EDT 2003
Hello;
I am trying to protect some global data, which may, in the future, be
accessed by threads. I'm not sure how to implement a locking mechanism
in python. Here is the idea I'm trying to express:
class resourceManager(object):
def __init__(self):
self.__resources = 100
def getResource(self):
BEGIN CRITICAL SECTION HERE
if self.__resources > 0:
self.__resources -= 1
* other related state information adjusted, too *
else:
emergencyCode()
END CRITICAL SECTION HERE
How is this accomplished? Does anyone know of a simple example?
Many thanks.
Brian.
More information about the Python-list
mailing list