Sujet : Re: Ported my proxy collector...
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++Date : 17. Sep 2024, 00:15:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcae5p$340q3$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 9/16/2024 4:08 PM, Chris M. Thomasson wrote:
This is a just quick port form Relacy to C++. The collector has the ability to allow a lock-free stack, queues, ect... to be used without any DWCAS on a pop operation. Also, it takes care of memory management issues with the nodes...
Well here is my crude test code. Keep in mind that the g_debug_alloc/free global's are only there for debugging purposes at this early stage. They can be removed. This is akin to a poor mans RCU, in a sense... Well, can you compile and run it when you get some really free time to burn?
Thanks everybody. :^)
_________________________________________
#include <cassert>
#include <iostream>
#include <atomic>
#include <thread>
#define CT_READERS 10
#define CT_WRITERS 10
#define CT_THREADS (CT_WRITERS + CT_READERS)
#define CT_ITERS 10000000
#define CT_COLLECT 10240
Fwiw, CT_COLLECT is how many times a collection is started per writer iteration wrt the following function:
// Push and pop nodes in the lock-free stack...
void
ct_thread_writer(
ct_shared& shared
) {
for (unsigned long i = 0; i < CT_ITERS; ++i)
{
// push
{
ct_proxy::node* n0 = new ct_proxy::node();
shared.m_stack.push(n0);
}
std::this_thread::yield();
// pop
{
ct_proxy::proxy::collector& c0 = shared.m_proxy.acquire();
shared.m_proxy.collect(c0, shared.m_stack.pop());
shared.m_proxy.release(c0);
}
if (! ((i + 1) % CT_COLLECT))
{
shared.m_proxy.collect();
}
}
}