Locking memory
[Runtime module API]


Detailed Description

Memory locking is implemented using compare and exchange methods.

Any time more than one object can concurrently write to the same region of memory, it is necessary to implement locking to prevent one object from overwriting the changes made by another. For example, more than one link can simultaneously update the admittance and current injection accumulators in nodes. Thus the following code is required to prevent two objects from simultaneously reading the same accumulator and posting their modifications without considering the other's contribution.

    complex I = to->V * Y;
    LOCK_OBJECT(from);
    from->Ys += Y;
    from->YVs -= I;
    UNLOCK_OBJECT(from);

Without locking, only the second one's contribution would be counted and the first one's would be lost.


Defines

#define LOCK(flags)   ((*(callback->lock_count))++, (*(callback->lock_spin))+=lock(flags))
 Locks an item.
#define LOCK_OBJECT(obj)   ((*(callback->lock_count))++, (*(callback->lock_spin))+=lock(&((obj)->flags)))
 Locks an object.
#define UNLOCK(flags)   unlock(flags)
 Unlocks an item.
#define UNLOCK_OBJECT(obj)   unlock(&((obj)->flags))
 Unlocks an object.


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy