From f25b88463064af20784387589cb6714d5ab74f6b Mon Sep 17 00:00:00 2001 From: fosanz Date: Fri, 24 Nov 2023 17:44:22 +0100 Subject: [PATCH] Initial commit --- lock.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lock.py diff --git a/lock.py b/lock.py new file mode 100644 index 0000000..4cfc7d1 --- /dev/null +++ b/lock.py @@ -0,0 +1,32 @@ +import threading + +class Cuenta: + + def __init__(self, saldoInicial): + self.saldo = saldoInicial + self.lock = threading.Lock() + + def depositar(self, cantidad): + self.lock.acquire() + self.saldo += cantidad + self.printSaldo() + self.lock.release() + + def extraer(self, cantidad): + self.lock.acquire() + if self.saldo < cantidad: + print("No hay saldo suficiente") + return False + self.saldo -= cantidad + self.printSaldo() + self.lock.release() + + def printSaldo(self): + print("El saldo es: ", self.saldo) + + + +cuenta = Cuenta(1000) +cuenta.printSaldo() +for i in range(10): + cuenta.extraer(100) \ No newline at end of file