put sema_up() inside while loop as well