Re: Futex Stack Test...

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Futex Stack Test...
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++
Date : 19. Feb 2025, 20:57:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vp5d3r$2dm82$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 2/17/2025 11:01 PM, Paavo Helde wrote:
On 18.02.2025 01:17, Chris M. Thomasson wrote:
This is a little C++20 test using a futex to allow one to wait on a lock-free stack. The main stack logic is in struct ct_stack. Well, can you get to compile and run? Thanks...
 Seamed to work fine, but compilation produced some warnings about the CT_WAIT macro.
[...]
Sorry about that. ;^o
Too used to C style casts. Thanks for giving it a go, Paavo. :^)
It's just an interesting way to use the std futex directly in the state of a lock-free stack. My code can be streamlined as well. For instance, the ct_stack::flush_wait function can be much better. Something like this, still not ideal, but a little better?
just typed this into the newsreader, but it should work fine:
_______________________
ct_node*
flush_wait()
{
     ct_node* head = m_head.exchange(nullptr, std::memory_order_acquire);
     while (! head || head == CT_WAIT)
     {
         // slow path...
         head = m_head.exchange(CT_WAIT, std::memory_order_acquire);
         if (! head || head == CT_WAIT)
         {
             m_head.wait(CT_WAIT, std::memory_order_relaxed);
         }
     }
     assert(head && head != CT_WAIT);
     return head;
}
_______________________
I think I could use a compare_exchange for the wait state in the slow-path, but trying to optimize a slow path is probably not even worth it all that much. Humm...

Date Sujet#  Auteur
18 Feb 25 * Futex Stack Test...20Chris M. Thomasson
18 Feb 25 +* Re: Futex Stack Test...5Paavo Helde
18 Feb 25 i+* Re: Futex Stack Test...2James Kuyper
19 Feb 25 ii`- Re: Futex Stack Test...1Chris M. Thomasson
19 Feb 25 i+- Re: Futex Stack Test...1Chris M. Thomasson
28 Feb 25 i`- Re: Futex Stack Test...1Chris M. Thomasson
2 May 25 `* Re: Futex Stack Test...14Wuns Haerst
2 May 25  +* Re: Futex Stack Test...2Chris M. Thomasson
2 May 25  i`- Re: Futex Stack Test...1Chris M. Thomasson
3 May 25  `* Re: Futex Stack Test...11Chris M. Thomasson
3 May 25   `* Re: Futex Stack Test...10Wuns Haerst
3 May 25    `* Re: Futex Stack Test...9Bonita Montero
3 May 25     `* Re: Futex Stack Test...8Chris M. Thomasson
3 May 25      `* Re: Futex Stack Test...7Bonita Montero
3 May 25       `* Re: Futex Stack Test...6Chris M. Thomasson
4 May 25        `* Re: Futex Stack Test...5Chris M. Thomasson
8 May 25         +* Re: Futex Stack Test...2Bonita Montero
8 May 25         i`- Re: Futex Stack Test...1Chris M. Thomasson
8 May 25         `* Re: Futex Stack Test...2jseigh
10 May 25          `- Re: Futex Stack Test...1Chris M. Thomasson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal