Add multithreadedMultiplication.py
This commit is contained in:
parent
f4f5d78f94
commit
0b930459c8
26
various other things/multithreadedMultiplication.py
Executable file
26
various other things/multithreadedMultiplication.py
Executable file
@ -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()
|
Loading…
Reference in New Issue
Block a user