From 3716bf8dd249953460b1df8c3c5d28f0abb662d6 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 24 Nov 2023 19:25:10 +0100 Subject: [PATCH] Initial commit --- EjercicioCajero.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 EjercicioCajero.py 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