# This is like ThirdSharedExample, only it uses locks to
# coordinate the processes.

from multiprocessing import *
import time

def F(r, 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,myLock))
        L.append(p)
    for p in L:
        p.start()
    

if __name__ == "__main__":
    main()
    input()

