...
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
#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 | ||||
---|---|---|---|---|
| ||||
struct multi_threaded_flagsMultiThreadedFlags { unsigned char flag1; unsigned char flag2; }; multi_threaded_flagsMultiThreadedFlags flags; void thread1() { flags.flag1 = 1; } void thread2() { flags.flag2 = 2; } |
...