You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
778 B

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")
self.lock.release()
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(20):
threading.Thread(target=cuenta.extraer, args=(100,)).start()

Powered by INFORMATICA.FP.EDU.ES.