Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"He don't know me vewy well, DO he?" -- Bugs Bunny


devel / comp.lang.c++ / Re: little tricks....

SubjectAuthor
* little tricks....Chris M. Thomasson
`- Re: little tricks....Chris M. Thomasson

1
little tricks....

<ul11br$242l0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2891&group=comp.lang.c%2B%2B#2891

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: little tricks....
Date: Fri, 8 Dec 2023 22:27:05 -0800
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ul11br$242l0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Dec 2023 06:27:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a7c294c6cac304dd766112d523acc79";
logging-data="2230944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GDnUKZJZygc6VNGGdsb6E3bWfsg4OQUk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vkiLu2z/NHlIZa17GYjN/s4wb/A=
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 9 Dec 2023 06:27 UTC

Food for thought. We can atomically increment a reference count along
with obtaining a reference to an object in a single fetch-and-add. All
in pure C++11

Say we have some objects:

collectors[CN];

And a reference count, say, 32 bit words:

RC = 0xRRRRRRCC

Where R is reference count space, and C is an index into collectors...

So, to obtain a reference we can simply:

word = fetch_and_add(&RC, 0x100);

Now we have incremented the count and obtained an index into the
collectors in one shot without DWCAS. ;^)

I cannot remember if this trick for single word proxy collectors is
patented!

Re: little tricks....

<ul11sq$242l0$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2892&group=comp.lang.c%2B%2B#2892

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: little tricks....
Date: Fri, 8 Dec 2023 22:36:09 -0800
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <ul11sq$242l0$2@dont-email.me>
References: <ul11br$242l0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Dec 2023 06:36:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a7c294c6cac304dd766112d523acc79";
logging-data="2230944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183utljaafHuXCRBdNYcsuJUXiVReJHUps="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ghoPlXWur/R1Sa5HhHKcYpPFxy4=
Content-Language: en-US
In-Reply-To: <ul11br$242l0$1@dont-email.me>
 by: Chris M. Thomasson - Sat, 9 Dec 2023 06:36 UTC

On 12/8/2023 10:27 PM, Chris M. Thomasson wrote:
> Food for thought. We can atomically increment a reference count along
> with obtaining a reference to an object in a single fetch-and-add. All
> in pure C++11
>
> Say we have some objects:
>
> collectors[CN];
>
>
> And a reference count, say, 32 bit words:
>
> RC = 0xRRRRRRCC
>
> Where R is reference count space, and C is an index into collectors...
>
> So, to obtain a reference we can simply:
>
> word = fetch_and_add(&RC, 0x100);

Fwiw, another trick is to increment by 0x200 and use the odd number
(0x300) for atomic quiescence detection. Proxy collectors sure beat the
heck out of rwlock when it comes down to the iteration of large
collections of nodes... Here is an example test unit in Relacy:

https://pastebin.com/raw/f71480694

If interested, take careful notice of the following functions:
________________
collector& acquire()
{
// increment the master count _and_ obtain current collector.
unsigned int current =
m_current.fetch_add(0x20U, std::memory_order_acquire);

// decode the collector index.
return m_collectors[current & 0xFU];
}

void release(collector& c)
{
// decrement the collector.
unsigned int count =
c.m_count.fetch_sub(0x20U, std::memory_order_release);

// check for the completion of the quiescence process.
if ((count & 0xFFFFFFF0U) == 0x30U)
{
// odd reference count and drop-to-zero condition detected!
prv_quiesce_complete(c);
}
}
________________

>
> Now we have incremented the count and obtained an index into the
> collectors in one shot without DWCAS. ;^)
>
> I cannot remember if this trick for single word proxy collectors is
> patented!
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor