# This is like GoodLockExample, only each process tries to
# create its own locks.  The program runs, but one processes
# locks don't block the other processes, so it doesn't count
# correctly.

from multiprocessing import *
import time

def F(r):
    lock = Lock()
    # This increments r 10 times

    for i in range(0, 10):
        lock.acquire()
        x = r.value
        y = x+1
        r.value = y
        print( "Process %d set r to %d" % (current_process().pid, r.value))
        lock.release()
        time.sleep(0.01)  # to model steps that take longer


def main():
    r = RawValue("i", 0)
    myLock = Lock()
    L = []
    for i in range(10):
        p = Process(target=F, args = (r,))
        L.append(p)
    for p in L:
        p.start()
    

if __name__ == "__main__":
    main()
    input()

