Search the web
Sign In
New User? Sign Up
liblf-dev · Lockfree data structure implementers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Lock-free ring buffer memory barriers test case   Message List  
Reply | Forward Message #282 of 300 |
Re: [liblf-dev] Lock-free ring buffer memory barriers test case

Many optimizing compilers will make things work, not because they
should work, but because optimizers like to remove operations and that
tends to make things more atomic. Plus, gcc, for example, tends to
insert memory barriers in places, like at function calls. In many
cases, things can work because datastructures happen to be stable
enough, even in light of weak ordering. However, all this is difficult
to predict -- especially if you want your app to be portable across
compilers and CPUs.

Occasionally, I've seen people comment that you have to let these
things run a really long time in order to see failure, but that's not
usually the case. Usually, if a test fails to fail (!) it's probably
because your compiler has done something, or you just haven't found a
case where it fails. Since absence of proof is not proof of absence,
and there were a lot of doubters out there, I wrote a counterexample
that failed on a standard PPC mac. You can find it if you search the
archives. I'm not sure anyone ever scrutinized it (even me -- I wrote
it super fast), so it may have done what it did due to a bug, but if
you doubt weak ordering I assure you very smart people have spent a
long time building it into the next revision of c++ and I don't think
they would have done that if it weren't necessary. But you can look at
my code if you doubt it, and if it happens to run on your machine,
you'll have to tweak it or take my word for it, as I no longer have
the machine that code used to run on.

bjorn

On Oct 28, 2008, at 9:06 AM, oja_i_i wrote:

> Hi,
>
> Can any of you advise a good test case that would demonstrate memory
> barriers are needed in a lock-free ring buffer ? I mean: a piece of
> code that would fail because memory barriers are missing.
>
> I wrote the following test, and it succeeds on PowerPC SMP (dual IBM
> Cell system QS-20), which is supposed to have weak memory ordering:
>
> http://svn.samalyse.com/misc/rbtest/test-int-array.c
>
> It is part of a (4 implementations) ring buffer test suite, that one
> can run with:
>
> svn co http://svn.samalyse.com/misc/rbtest
> cd rbtest
> make test
>
> Best regards,
>
> --
> Olivier Guilyardi / Samalyse
>

-----------------------------
Bjorn Roche
XO Wave
Digital Audio Production and Post-Production Software
http://www.xowave.com
http://blog.bjornroche.com
http://myspace.com/xowave





Wed Oct 29, 2008 6:37 pm

bejayoharen
Offline Offline
Send Email Send Email

Forward
Message #282 of 300 |
Expand Messages Author Sort by Date

Hi, Can any of you advise a good test case that would demonstrate memory barriers are needed in a lock-free ring buffer ? I mean: a piece of code that would...
oja_i_i
Offline Send Email
Oct 29, 2008
3:44 am

Many optimizing compilers will make things work, not because they should work, but because optimizers like to remove operations and that tends to make things...
Bjorn Roche
bejayoharen
Offline Send Email
Oct 29, 2008
6:37 pm

... Thanks for your answer. Is this the counter example you mention: http://tech.groups.yahoo.com/group/liblf-dev/message/203 ? -- Olivier Guilyardi / Samalyse...
oja_i_i
Offline Send Email
Oct 30, 2008
2:12 pm

... Gosh that's hard to read without the tabs! I think that was just a standard ringbuffer, not a proof that memory barriers are needed design. bjorn ... Bjorn...
Bjorn Roche
bejayoharen
Offline Send Email
Oct 30, 2008
3:21 pm

... I really don't think so. citation? --...
James McCartney
james_e_mcca...
Offline Send Email
Oct 30, 2008
9:20 pm

... I can't find a citation right now, so I could be wrong. If I am wrong, sorry about that. It's obviously not behavior to count on anway, since even if you...
Bjorn Roche
bejayoharen
Offline Send Email
Oct 31, 2008
2:34 pm

... Even with -O0? Steve...
Stephen Sinclair
sinclairs828
Offline Send Email
Nov 1, 2008
6:17 am

... I've read so many citations, and other theories about ring buffers and memory barriers. But to me they're useless until someone can write a piece of code...
oja_i_i
Offline Send Email
Nov 1, 2008
6:17 am

Hello, I just saw this postedon reddit, I'm not sure but I thought it might be relevant to this discussion. ...
Stephen Sinclair
sinclairs828
Offline Send Email
Nov 6, 2008
6:57 am

There are two files in the file section of this list. I scanned the emails of this list quickly and I think they both ran fine for many people and failed for...
Bjorn Roche
bejayoharen
Offline Send Email
Nov 6, 2008
3:18 pm

I don't think so either. I'd be surprised if gcc inserts any memory barriers. But I do remember reading somewhere that a C optimizer probably won't reorder...
Ross Bencina
ross_bencina
Offline Send Email
Nov 1, 2008
6:15 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help