c++ - How to make atomic getters and setters in a singleton? -


i have struct of getters , setters use use std::unique_lock lock access. getters shared same lock made request singleton serialized. mentioned solution worked slow. worried dead locks since of access data structure reads. i'd 70% of access reads. started looking atomic operations b\c there buzz lock free synchronization.

i've noticed massive slow down in code base. first let me preempt suggestions architecture. code runs on x86 not memory fence issue. second i'm using acquire semantics loads , release semantics stores, , x86 explicitly guarantees no memory fences for.

my theory i'm not using right memory_order want or @ least how library used in practice or has compiler.

so i'm using msvc 2015 update 2 compiler , slow down prevalent on debug builds.

struct singleton_struct     {         std::atomic_bool m_bis1;         std::atomic_bool m_bis2;         std::atomic_bool m_bis3;         singleton_struct() : m_bis1(false), m_bis2(false), m_bis3(false) {};          void set1(bool bis1);         void set2(bool bis2);         void set3(bool bis3);          bool is1();         bool is2();         bool is3();     }  singleton_struct::set1(bool bis1) {     m_bis1.store(bis1, std::memory_order_release);  }  singleton_struct::set2(bool bis2) {     m_bis2.store(bis2, std::memory_order_release);  }  singleton_struct::set3(bool bis3) {     m_bis3.store(bis3, std::memory_order_release);  }  bool singleton_struct::is1() {     return m_bis1.load(std::memory_order_acquire);  }  bool singleton_struct::is2() {     return m_bis2.load(std::memory_order_acquire);  }  bool singleton_struct::is3() {     return m_bis3.load(std::memory_order_acquire);  } 


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -