Is this a safe way to ensure that the master thread will never miss a wake up signal if no other thread uses the variable flag?

```
void *Cancel_master_thread(void *arg)
{
  while (1)
  {
    flag = 0;
    pthread_mutex_lock(&cancel_in_progress);
    flag = 1;
    pthread_cond_wait(&cancel_finished, &cancel_in_progress);
    pthread_mutex_unlock(&cancel_in_progress);
  }
}

void *Cancel_slave_MB()
{
  while (1)
  {
    while (flag != 1)
    {
    }

    pthread_mutex_lock(&cancel_in_progress);
    pthread_cond_signal(&cancel_finished);
    pthread_mutex_unlock(&cancel_in_progress);
  }
}

```