Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Coding style conformance

...

Code Block
bgColor#FFcccc
langc
struct multi_threaded_flagsMultiThreadedFlags {
  unsigned int flag1 : 2;
  unsigned int flag2 : 2;
};

multi_threaded_flagsMultiThreadedFlags flags;

void thread1() {
  flags.flag1 = 1;
}

void thread2() {
  flags.flag2 = 2;
}

...

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

struct mtf_mutexMtfMutex {
  multi_threaded_flagsMultiThreadedFlags s;
  std::mutex mutex;
};

mtf_mutexMtfMutex flags;

void thread1() {
  std::lock_guard<std::mutex> lk(flags.mutex);
  flags.s.flag1 = 1;
}
 
void thread2() {
  std::lock_guard<std::mutex> lk(flags.mutex);
  flags.s.flag2 = 2;
}

...

Code Block
bgColor#ccccff
langc
struct multi_threaded_flagsMultiThreadedFlags {
  unsigned char flag1;
  unsigned char flag2;
};
 
multi_threaded_flagsMultiThreadedFlags flags;
 
void thread1() {
  flags.flag1 = 1;
}

void thread2() {
  flags.flag2 = 2;
}

...