from multiprocessing import Process, Value, Lock

class Counter(object):

    def __init__(self, initval=0):
    
        self.val = Value('i', initval)
        self.lock = Lock()

    # end def __init__
    
    
    def increment(self):
    
        with self.lock:
            self.val.value += 1
        # end with

    # end def increment
    
    
    def value(self):
    
        with self.lock:
            return self.val.value
        # end with
        
    # end def value
    
# end class Counter


def func(counter):
    
    for i in range(50):
        time.sleep(0.01)
        counter.increment()
    # end for
    
# end def func


if __name__ == '__main__':

    counter = Counter(0)
    procs = [Process(target=func, args=(counter,)) for i in range(10)]

    for p in procs:
        p.start()
    # end for
    
    for p in procs:
        p.join()
    # end for

    print counter.value()
    
# end if