Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68407

Re: std::thread - DESPERATE NEED HELP!!!

From "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups comp.lang.c++
Subject Re: std::thread - DESPERATE NEED HELP!!!
Date 2019-09-13 22:17 -0700
Organization Aioe.org NNTP Server
Message-ID <qlht56$fii$1@gioia.aioe.org> (permalink)
References <NRaeF.332144$R83.166244@fx23.am4> <2hZeF.171439$423.71319@fx07.iad> <qlhsjd$d5m$1@gioia.aioe.org>

Show all headers | View raw


On 9/13/2019 10:07 PM, Chris M. Thomasson wrote:
> On 9/13/2019 8:38 PM, Pavel wrote:
[...]
>> Sub-Note: sometimes (but I think, not in your case) it is correct to
>> wait for signal not in a loop --
> 
> Using condition variables directly? If the code thinks that the return 
> from a condvar wait means a signal was actually sent, well, this is 
> mistaken. However, there is something called the eventcount, that can 
> abuse a condvar wait. The predicate is atomic.

The loop is different in an eventcount, iirc its something like:

imagine trying to pop from any lock-free collection, and you want to 
make it wait on an empty condition, well:

// quick pseudo-code
____________________________________________
eventcount ec;

node* n = null;

// FAST PATH
while ((n = try_pop()) == null)
{
     // SLOW PATH
     eventcount_key eckey = ec.begin();

     if ((n = try_pop()) != null)
     {
         ec.leave(eckey);
         break;
     }

     // wait for it!
     ec.wait(eckey);
}

// n is an actual node we just popped! nice. :^)
____________________________________________

The double check for the predicate is required here. An eventcount is 
like a condition variable for lock-free algorithms.


> 
> [...]

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

std::thread - DESPERATE NEED HELP!!! Szyk Cech <szykcech@spoko.pl> - 2019-09-11 20:16 +0200
  Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-11 23:01 -0700
  Re: std::thread - DESPERATE NEED HELP!!! Ralf Fassel <ralfixx@gmx.de> - 2019-09-12 11:14 +0200
  Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 12:53 -0700
  Re: std::thread - DESPERATE NEED HELP!!! Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-13 23:38 -0400
    Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 22:07 -0700
      Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 22:17 -0700
        Re: std::thread - DESPERATE NEED HELP!!! "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-13 23:01 -0700

csiph-web