I have several workers process which should decrease a shared integer when the are finished.
To ensure Threadsafety i tried a lock but somehow it is not working, printing out workers at the end of the program will still output 4
workers = 4
lock = threading.Lock()
def workerStopped(id,lock):
lock.acquire()
global workers
print "Decrease workers (" + str(workers) + ")for #" + str(id)
workers = workers - 1
print "Now " + str(workers) + " Workers"
lock.release()
class Worker(Process):
def __init__(self, queue,ident,lock):
super(Worker, self).__init__()
self.queue= queue
self.idstr= str(ident)
self.lock = lock
print "Ident" + self.idstr
......
workerStopped(self.idstr,self.lock)
....
for i in range(4):
Worker( request_queue,i,lock ).start()