Skip to content

hatomic.h windows下原子操作错误 #581

Open
@Cracal

Description

@Cracal

不同长度的整型使用这些原子操作接口时得到的结果不正确。
比如:atomic_flag_test_and_set函数(内部代码:InterlockedCompareExchange((LONG*)&p->_Value, 1, 0))调用后并不能让atomic_flag置1。

还有这些原子操作接口在不同平台下的返回值不同。比如我用来实现引用计数的代码:

if (ATOMIC_DEC(&ref->refcnt) == 1)
{
    release_cb(ref);
}

在linux下,ATOMIC_DEC返回的减少之前的值,而在windows下返回的是减少之后的值,这导致这段代码在Windows下不正确。

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