commit 3716bf8dd249953460b1df8c3c5d28f0abb662d6 Author: Victor Date: Fri Nov 24 19:25:10 2023 +0100 Initial commit diff --git a/EjercicioCajero.py b/EjercicioCajero.py new file mode 100644 index 0000000..d3fb78b --- /dev/null +++ b/EjercicioCajero.py @@ -0,0 +1,25 @@ +from threading import Lock, Thread +import threading +import time + +def retirarDinero(retirar,lock): + with lock: + global dineroTotal + if dineroTotal == 0: + print("Saldo insuficiente") + else: + print("Dinero retirado") + dineroTotal = dineroTotal-retirar + + + +lock = threading.Lock() +dineroTotal = 1000 +retDinero = 200 + +for i in range(3): + t = threading.Thread(retirarDinero(retDinero,lock)) + t2 = threading.Thread(retirarDinero(retDinero,lock)) + t.join + t2.join + \ No newline at end of file