Skip to content

RefCounted release is not atomic #63

@submada

Description

@submada

RefCounted.release method is not atomic.

    void release() {
		/*
		...
		*/

        dec;
        if(_impl._count == 0) {
			/*
			...
			*/
        }
    }

calling "dec" is atomic and "_impl._count == 0" is atomic but together they are not atomic.

Something like this is necessary:

if(atomicFetchSub!(MemoryOrder.acq_rel)(_impl._count , 1) == 1){ //... }
Clang use it too:
https://github.com/llvm-mirror/libcxx/blob/master/include/memory#L3398

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions