Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #119
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
| From | Andy Venikov <swojchelowek@gmail.com> |
| Newsgroups | comp.programming.threads |
| Subject | Re: What's the latest state-of-the art for EventCounts? |
| Date | Thu, 05 May 2011 12:01:34 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 71 |
| Message-ID | <ipuhl0$tvm$1@dont-email.me> (permalink) |
| References | <ipffi8$98t$1@dont-email.me> <ipmg67$gl9$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 5 May 2011 16:01:37 +0000 (UTC) |
| Injection-Info | mx03.eternal-september.org; posting-host="pJbf3YDVQ6EpKK7Z5djemQ"; logging-data="30710"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lZqOX8cDC5Ezp7maQ91/ldljmyVQ0tNQ=" |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 |
| In-Reply-To | <ipmg67$gl9$1@dont-email.me> |
| Cancel-Lock | sha1:6ED2FVJ51qupapXjo7M3dmRX57U= |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:119 |
Show key headers only | View raw
On 05/02/2011 10:47 AM, Andy Venikov wrote:
> On 04/29/2011 06:53 PM, Andy Venikov wrote:
>> There are several implementations out there.
>> Notably by Joe Seigh as part of his library.
>> Also several posts by Dmitry and Chris.
>> I also saw one by Rani Sharoni.
>>
>> Is there a consensus what's currently the best algorithm?
>>
>> Thanks,
>> Andy.
>
> Since the platform I care about is Linux, I think I could just use
> futexes. I mean, futex is just an implementation of an event count.
> Of course it's much more than that, but it can easily translate
> itself to an event count. No?
>
> Thanks,
> Andy.
What I meant was something like this.
Assume we have a lock-free queue "Queue".
Queue queue;
int ec = 0; //1 means waiting
//consumer(s):
while (true)
{
SomeData data;
while (!queue.try_deque(&data)) //it's also a full barrier
{
ec = 1; //atomic write
//place StoreLoad barrier here
if (!queue.try_deque(&data))
{
futex(FUTEX_WAIT, &ec, 1);
}
else
{
break;
}
}
process(data);
}
//producer(s):
queue.enqueue(data); //full barrier
int ecValue = ec; //atomic read
if (0 != ecValue)
{
ecValue = atomic_exchange(&ec, 0);
}
if (0 != ecValue)
{
futex(FUTEX_WAKE, &ec);
}
Of course the consumer could be optimized by not entering the wait right
away but rather trying to dequeue a few more times with a cpu_relax
thrown in the mix, but you get the idea.
I'm more concerned with the correctness.
This algorithm can allow one consumer to unnecessarily wake one extra
waiter that might go immediately back to sleep, but that won't break
correctness. (The producer may signal a wake even though the item was
picked out of the queue by a non-sleeping thread).
Otherwise it looks correct to me.
Any thoughts?
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