<reponame>TeamFat/learning-golang<filename>pythoncode/python2.7/python-multithreading/8.py
import threading
#http://codingpy.com/article/python-201-a-tutorial-on-threads/
total = 0
lock = threading.Lock()

def update_total(amount):
    """
    Updates the total by the given amount
    """
    global total
    lock.acquire()
    try:
        total += amount
    finally:
        lock.release()
    print (total)

if __name__ == '__main__':
    for i in range(10):
        my_thread = threading.Thread(
            target=update_total, args=(5,))
        my_thread.start()
import threading
#http://codingpy.com/article/python-201-a-tutorial-on-threads/
total = 0
lock = threading.Lock()

def update_total(amount):
    """
    Updates the total by the given amount
    """
    global total
    lock.acquire()
    try:
        total += amount
    finally:
        lock.release()
    print (total)

if __name__ == '__main__':
    for i in range(10):
        my_thread = threading.Thread(
            target=update_total, args=(5,))
        my_thread.start()
#http://codingpy.com/article/python-201-a-tutorial-on-threads/ Updates the total by the given amount