For now, atomic_init() will be supported as simply a relaxed write. This
doesn't quite match the spec exactly [1, 2], but it is expedient for supporting
the common case of checking proper initialization.
[1] From C++ N3242, Section 29.6.5, Statement 8:
Non-atomically initializes *object with value desired.
Note: Concurrent access from another thread, even via an atomic
operation, constitutes a data race.
[2] Note that for now, my implementation will not flag concurrent atomic_init()
and atomic_store() as data races.
bool ModelAction::is_write() const
{
- return type == ATOMIC_WRITE;
+ return type == ATOMIC_WRITE || type == ATOMIC_INIT;
}
bool ModelAction::is_rmw() const
return type == ATOMIC_RMW;
}
+bool ModelAction::is_initialization() const
+{
+ return type == ATOMIC_INIT;
+}
+
bool ModelAction::is_acquire() const
{
switch (order) {
case ATOMIC_RMW:
type_str = "atomic rmw";
break;
+ case ATOMIC_INIT:
+ type_str = "init atomic";
+ break;
default:
type_str = "unknown type";
}
THREAD_JOIN,
ATOMIC_READ,
ATOMIC_WRITE,
- ATOMIC_RMW
+ ATOMIC_RMW,
+ ATOMIC_INIT
} action_type_t;
/* Forward declaration */
bool is_read() const;
bool is_write() const;
bool is_rmw() const;
+ bool is_initialization() const;
bool is_acquire() const;
bool is_release() const;
bool is_seqcst() const;
void atomic_init(struct atomic_object *obj, int value)
{
+ DBG();
obj->value = value;
+ model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, value));
}