Fixed deadlock, switched signal to broadcast and implemented mutual exclusion for each function.