On multicore MacOSX, is the following c++ code threadsafe?
-
23-09-2019 - |
문제
#define atomicAdd OSAtomicAdd32Barrier
class PtrInterface: public Uncopyable {
private:
typedef volatile int RefCount;
mutable RefCount rc;
public:
inline void newRef() const { atomicAdd(1, &rc); }
inline void deleteRef() const { atomicAdd(-1, &rc); }
};
[This is the basis of an invasive refcounted pointer; I just want to make sure the refcounts are not off]
올바른 솔루션이 없습니다
다른 팁
It looks OK from here. There are many public examples you can use (such as counter_t
from the Adobe Source Libraries) to futher improve upon your implementation.
제휴하지 않습니다 StackOverflow