Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

C Concurrency Less Big Fail

DZone's Guide to

C Concurrency Less Big Fail

·
Free Resource

int64_t AddAndGetAtomic(Object *o, int64_t amount) {
    int64_t oldval;
    int64_t returnval;
    bool success = 0;
    do {
        oldval = o->counter;
        returnval = oldval + amount;
        success = OSAtomicCompareAndSwap64(oldval, returnval, &(o->counter);
    } while (success == 0);

    return returnval;
}
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}