26 lines
782 B
Python
Executable File
26 lines
782 B
Python
Executable File
#!/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() |