- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
template<class T, size_t N>
constexpr size_t sa(T (&)[N])
{
return N;
};
static std::memory_order mmo[] =
{
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
};
std::memory_order current_program_memory_order()
{
return mmo[rand()%sa(mmo)];
}
void current_program_memory_barier()
{
std::atomic_thread_fence(current_program_memory_order());
}
LispGovno 23.02.2015 12:10 # 0
bormand 23.02.2015 12:22 # +1
LispGovno 23.02.2015 12:25 # 0
std::atomic_thread_fence<std::memory_ord er_seq_cst>(); вместо std::atomic_thread_fence(std::memory_ord er_seq_cst);
bormand 23.02.2015 12:54 # +1
guest 24.02.2015 15:50 # +1
Note that the C++11 standard allows for the memory model parameter to be determined at run time rather than at compile time. These built-in functions map any run-time value to __ATOMIC_SEQ_CST rather than invoke a runtime library call or inline a switch statement. This is standard compliant, safe, and the simplest approach for now.