Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #122
| From | Andy Venikov <swojchelowek@gmail.com> |
|---|---|
| Newsgroups | comp.programming.threads |
| Subject | Re: What's the latest state-of-the art for EventCounts? |
| Date | 2011-05-06 14:24 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iq1ec6$aoo$1@dont-email.me> (permalink) |
| References | <ipffi8$98t$1@dont-email.me> <ipmg67$gl9$1@dont-email.me> <ipuhl0$tvm$1@dont-email.me> <a1Jwp.11661$Du7.10698@newsfe04.iad> |
On 05/05/2011 10:29 PM, Chris M. Thomasson wrote:
> "Andy Venikov"<swojchelowek@gmail.com> wrote in message
<snip>
>
> I have not programmed threads for a couple of month's now, so please forgive
> me if I am way off base here... ;^)
Welcome back :-)
I've started to miss the great discussions between you and Dmitry.
>
> I do not think that algorithm will work _unless_ the call to
> `futex(FUTEX_WAKE,&ec)' wakes _all_ of the current waiters. I think you
> have to explicitly specify the number of waiters:
>
> http://www.kernel.org/doc/man-pages/online/pages/man2/futex.2.html
>
> So a call like:
> _________________________________________________
> #define futex_broadcast(f) \
> futex((f), FUTEX_WAKE, INT_MAX, NULL, NULL, 0)
>
>
> futex_broadcast(&ec);
> _________________________________________________
>
> might be in order... Humm... What do you think? I am thinking about a
> scenario in which 3 threads hit an empty queue and wait. Now the state is
> three waiter threads; empty queue with an `ec' value of 1. Then another
> thread produces something, see's `ec' as 1 and atomically resets it and then
> releases a single waiter that dequeues said item. Then three more producer
> threads come along and enqueue items but observes `ec' as 0. Now you have 3
> items in the queue, and 2 "stalled" waiters... Humm...
>
> Need to think some more on this.
Yup, you're right.
The reason for my error was that in my real problem there is just one
consumer, and the queue is MPSC. The consumer would actually not do
anything in terms of processing the data, but queue it off to others,
acting as a sort-of a dispatcher. So it would quickly exhaust the queue
if there was anything in it.
And right before posting I thought hmmm, looks like this could work for
multiple consumers as well.... Wrong!
I think in order to make this solution multi-consumer-friendly, we have
to play tricks with "ec" and make it a real counter to indicate the
amount of waiters. I'll think about it over the week-end.
Of course, it could be used as-is with "wake everybody" semantics, but
then we would get the "thundering herd" problem, which is usually not
a simple problem to solve either.
Thanks,
Andy.
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-04-29 18:53 -0400
Re: What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-05-02 10:47 -0400
Re: What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-05-05 12:01 -0400
Re: What's the latest state-of-the art for EventCounts? "Chris M. Thomasson" <cristom@charter.net> - 2011-05-05 19:29 -0700
Re: What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-05-06 14:24 -0400
Re: What's the latest state-of-the art for EventCounts? "Chris M. Thomasson" <cristom@charter.net> - 2011-05-07 16:49 -0700
Re: What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-05-09 19:05 -0400
Re: What's the latest state-of-the art for EventCounts? "Chris M. Thomasson" <cristom@charter.net> - 2011-05-09 16:28 -0700
Re: What's the latest state-of-the art for EventCounts? Andy Venikov <swojchelowek@gmail.com> - 2011-05-11 19:28 -0400
Re: What's the latest state-of-the art for EventCounts? "Chris M. Thomasson" <cristom@charter.net> - 2011-06-09 19:09 -0700
Re: What's the latest state-of-the art for EventCounts? Keith H Duggar <duggar@alum.mit.edu> - 2011-07-30 19:15 -0700
csiph-web