Is this thread safe or are there bugs in here? template <typename VOIDHND> class…
- User
Is this thread safe or are there bugs in here?
template class AtomicHndStack2 { using VoidHndPair = std::pair<VOID_HND, VOID_HND>; //TODO what's the first??? std::atomic<VOID_HND> _head{};
public: void Push(VOID_HND hnd) { NextOf(hnd) = _head.load(); while (!_head.compare_exchange_weak(NextOf(hnd), hnd)); }
codeVOID_HND Pop() { auto p = _head.load(); while (p != nullptr && !_head.compare_exchange_strong(p, NextOf(p))) {} return p; } [[nodiscard]] int SizeUnsafe() { int s = 0; for (VOID_HND c = _head; c != nullptr; c = NextOf(c)) s++; return s; }private: static VOID_HND& NextOf(VOID_HND hnd) { return static_cast<VoidHndPair*>(hnd.GetUnsafe())->second; } };
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.