...
Code Block | ||||
---|---|---|---|---|
| ||||
#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; } |
...