Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: exceptions are 0-offset

...

Code Block
bgColor#ccccff
langc
#include <stdatomic.h>
#include <threads.h>
 
atomic_flag flag = ATOMIC_VAR_INIT(0);

int func(void *data) {
  while (!flag) {
    /* ... */
  }
  return 0;
}

int main(void) {
  int result;
  thrd_t tid;
  
  if (thrd_success != thrd_create(&tid, func, NULL)) {
    /* Handle Error */
  }

  /* ... */

  /* Set flag when done. */
  while (!atomic_flag_test_and_set(&flag))
    ; /* Continue attempts. */

  return 0;
}

Exceptions

CON37-EX1EX0: Platforms that provide defined behavior when multithreaded programs use custom signal handlers are exempt from this rule. This would include POSIX, for example.

...