Repairing the check-then-sleep race

A single-threaded POSIX program initializes a static volatile sig_atomic_t flag named ready to 0. Its installed SIGUSR1 handler assigns 1 to that flag and returns. SIGUSR1 is initially unblocked. A sender will generate exactly one notification after handler installation, and no other signals occur. The program waits using this code:


C
while (!ready)
    pause();


Which statements correctly describe this code or a repair? Select all that apply. Assume all setup calls succeed and every supplied signal set is valid.

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Signal Handling Questions: