diff --git a/ejercicios_hilos/ej03.py b/ejercicios_hilos/ej03.py new file mode 100644 index 0000000..df6cff7 --- /dev/null +++ b/ejercicios_hilos/ej03.py @@ -0,0 +1,38 @@ +import threading +import time +import random + +def tareaUno(): + global Done + time.sleep (random.random()) + if not Done: + print("Tarea realizada") + time.sleep(0.1) + Done = True + else : + print ("tarea NO REALIZADA") + time.sleep(0.01) + return + +def tareaDos(): + global Done + Done = False + print("Desactivo") + +hilos1 = list() +for i in range(50): + t = threading.Thread(target=tareaUno) + hilos1.append(t) + t.start() + +Done = False +tareaUno() + +hilos2 = list() +for i in range(5): + t2 = threading.Thread(target=tareaDos) + hilos2.append(t2) + t2.start() + time.sleep(1) + +time.sleep(6) \ No newline at end of file