diff --git a/various other things/multithreadedMultiplication.py b/various other things/multithreadedMultiplication.py new file mode 100755 index 0000000..1e9b09d --- /dev/null +++ b/various other things/multithreadedMultiplication.py @@ -0,0 +1,26 @@ +#!/bin/python +import threading +from time import sleep +baseGlobal = {0: 0, 1: 0} +sleepTime = 1 +#Initialize functions that we will execute as threads: +def mult(num1,threadOffset): + global baseGlobal,sleepTime + while True: + num1 *= 2 + baseGlobal[threadOffset] = num1 + sleep(int(sleepTime)) +def printOutput(): + while True: + print("Multiples of 8: "+str(baseGlobal[0]), end="") + print(" Multiples of 32: "+str(baseGlobal[1]), end="\r", flush=True) +print("Multithreaded Multiplication"+"\n") +if __name__ == "__main__": + #Create Threads + t1 = threading.Thread(target=mult, args=(8,0)) + t2 = threading.Thread(target=mult, args=(32,1)) + t3 = threading.Thread(target=printOutput, args=()) +#Start Threads +t1.start() +t2.start() +t3.start() \ No newline at end of file