コード例 #1
0
def main():
    
    num_channel = int(raw_input("Quantidade de canais: "))
    num_guests = int(raw_input("Quantidade de hospedes: "))
    min_watch_time = int(raw_input("Tempo minimo para assistir: "))
    max_watch_time = int(raw_input("Tempo maximo para assistir: "))
    min_rest_time = int(raw_input("Tempo minimo de descanso: "))
    max_rest_time = int(raw_input("Tempo maximo de descanso: "))
    
    
    for i in range(num_guests):
        t = Guest(randint(1, num_channel), randint(min_watch_time, max_watch_time), randint(min_rest_time, max_rest_time))
        t.start()
    
    Guest().start()
    
    print "Favorite channel: %s" %t.favorite_channel
    print "Rest time: %s" %t.rest_time
    print "Watch time: %s" %t.watch_time
    
    take_control = threading.Lock()
    mutex = threading.Lock()
    watching = 0
    
    def watch_channel():
        while True:
            mutex.acquire(True) 
            watching += 1
            if watching == 1:
                take_control.release(True)
            mutex.release()
            
            #seta_canal()
            watching -= 1
            if watching == 0:
                take_control.release(True)
            mutex.release(True)
            #assiste_tv()
            
    def set_channel():
        while True:
            take_control.acquire(True)
            #seta_canal()
            take_control.release(True)