Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed variable names to be more consistent with C++ standard terminology

...

Code Block
bgColor#ccccff
langc
#include <mutex>
 
struct multi_threaded_flags {
  unsigned int flag1 : 2;
  unsigned int flag2 : 2;
};

struct mtf_mutex {
  struct multi_threaded_flags s;
  std::mutex mutex;
};

struct mtf_mutex flags;

int thread1(void *arg) {
  std::lock_guard<std::mutex> guardlk(flags.mutex);
  flags.s.flag1 = 1;
  return 0;
}
 
int thread2(void *arg) {
  std::lock_guard<std::mutex> guardlk(flags.mutex);
  flags.s.flag2 = 2;
  return 0;
}

...