commit f25b88463064af20784387589cb6714d5ab74f6b Author: fosanz Date: Fri Nov 24 17:44:22 2023 +0100 Initial commit 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