Re: [LAU] Simple, easy multithreaded circular buffer library for Linux?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Paul Coccoli <pcoccoli@...>
Cc: A list for linux audio users <linux-audio-user@...>
Date: Saturday, October 18, 2008 - 4:47 pm

On Fri, 2008-10-17 at 14:33 -0400, Paul Coccoli wrote:

I don't believe this logic is correct.

As I explained before, and as Fons reiterated, the code is safe because
of the combination of (a) single-writer, single-reader semantics and (b)
any errors caused by context switching a the wrong time cause an
under-estimate rather than an over-estimate of the current situation
vis-a-vis reading or writing.

The fact that in the revised version read_ptr is only read once changes
nothing, since only thread ever modifies read_ptr. It doesn't matter how
many times it accessed to do the computation - it will NEVER change its
value during this computation because the computation happens in the
reader thread and the reader thread is the only place where read_ptr is
modified.

So, its interesting that this revised version passes the test, but I
don't believe that this is the reason why it does so.

The test that Olivier has written is essentially a no-op on a
uniprocessor x86 system, because there are no cache coherency issues.
The code *is* thread safe on a uniprocessor because of the logic above,
not because we rely on instruction reordering/memory barrier processor
behaviour.

However, on an SMP system, the logic that applies to the single
reader/single writer design may not be sufficient to ensure correctness,
hence the interest in adding memory barriers to the code. I believe that
PortAudio is correct to do this.

Before we do this, though, we should determine why the current code can
fail, and whether the "fix" mentioned above is actually a fix or simply
changes the code enough to hide the real problem more frequently (which
I suspect is the case).

--p

_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-user

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [LAU] Simple, easy multithreaded circular buffer library..., Kjetil S. Matheussen, (Tue Oct 14, 4:39 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Tue Oct 14, 9:01 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Wed Oct 15, 11:03 am)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Wed Oct 15, 11:49 am)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 12:13 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 5:20 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Joern Nettingsmeier, (Fri Oct 17, 6:02 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Paul Davis, (Sat Oct 18, 4:47 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Joern Nettingsmeier, (Sat Oct 18, 5:08 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Joern Nettingsmeier, (Fri Oct 17, 7:22 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Joern Nettingsmeier, (Fri Oct 17, 10:32 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 6:37 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 5:45 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 2:39 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Sun Oct 19, 11:03 am)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 5:35 pm)
[LAU] [LAA] gxtuner-1.6 update, hermann, (Sun Dec 11, 8:20 am)
Re: [LAU] [LAD] gxtuner-1.6 update, hermann, (Wed Dec 14, 1:29 pm)
[LAU] gxtuner-1.5 released, hermann, (Fri Dec 9, 11:17 am)
Re: [LAU] [LAD] gxtuner-1.5 released, Jostein Chr. Andersen, (Fri Dec 9, 2:43 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, hermann, (Fri Dec 9, 3:30 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, Jostein Chr. Andersen, (Fri Dec 9, 8:28 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, Gerhard Zintel, (Sat Dec 10, 12:17 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, Jostein Chr. Andersen, (Sat Dec 10, 11:14 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, Jostein Chr. Andersen, (Sat Dec 10, 11:07 pm)
Re: [LAU] [LAD] gxtuner-1.5 released, hermann, (Fri Dec 9, 9:29 pm)
Re: [LAU] [LAA] [ANN] guitarix release guitarix2-0.18.0, Jeremy Jongepier, (Tue Sep 6, 11:23 am)
[LAU] update release gxtuner-1.3, hermann, (Thu Jul 28, 7:56 am)
[LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Sun Jul 24, 11:12 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, R.Wolff, (Mon Jul 25, 11:12 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Mon Jul 25, 5:54 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, allcoms, (Wed Jul 27, 10:08 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 11:06 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, allcoms, (Wed Jul 27, 2:33 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 6:04 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 2:54 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, Fons Adriaensen, (Wed Jul 27, 10:13 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 11:19 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, Fons Adriaensen, (Wed Jul 27, 11:58 am)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 12:49 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, Fons Adriaensen, (Wed Jul 27, 2:21 pm)
Re: [LAU] [LAA] [ANN] release gxtuner-1.0, hermann, (Wed Jul 27, 3:14 pm)
Re: [LAU] [LAA] [ANN] guitarix release guitarix2-0.17.0, Alexandre Prokoudine, (Sat Jul 9, 6:50 pm)
[LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Fri Jan 14, 8:36 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Mon Jan 17, 11:13 am)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, Mark Knecht, (Sun Jan 16, 6:31 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Sun Jan 16, 8:22 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, Ivan Tarozzi, (Sun Jan 16, 7:04 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, Ivan Tarozzi, (Sun Jan 16, 6:18 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, Ivan Tarozzi, (Mon Jan 17, 1:35 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Tue Jan 18, 6:53 am)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Sun Jan 16, 8:04 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, Jeremy Jongepier, (Sun Jan 16, 10:08 am)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Sun Jan 16, 11:48 am)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Sun Jan 16, 8:08 pm)
Re: [LAU] [LAA] [ANN] guitarix released gx_head, hermann, (Sun Jan 16, 8:25 pm)
[LAU] [LAA] [ANN] guitarix-0.10.0 released, hermann, (Sun Jul 11, 4:45 am)
[LAU] guitarix-0.08.0 release 'Rockers', hermann, (Fri May 14, 2:44 pm)
[LAU] [LAA] [ANN] guitarix-0.06.0 bugfix release, hermann, (Thu Feb 18, 8:08 pm)
[LAU] [LAA] [ANN] guitarix-0.05.9-1 release, hermann, (Thu Feb 18, 6:11 am)
[LAU] [LAA] [ANN] guitarix-0.05.6-1 released, hermann, (Fri Jan 1, 11:44 am)
[LAU] [LAA] [ANN] guitarix-0.05.2-1 released, hermann, (Sun Dec 13, 10:45 am)
[LAU] [LAA] [ANN] guitarix-0.05.2-1 released, hermann, (Mon Nov 30, 12:44 pm)
Re: [LAU] [LAA] [ANN] guitarix-0.05.2-1 released, Hartmut Noack, (Thu Dec 3, 1:05 pm)
[LAU] [ANN] guitarix-0.05.1-1 released, hermann, (Mon Oct 26, 7:52 am)
[LAU] [LAA] [ANN] guitarix-0.05.0-1 released, hermann, (Mon Jul 27, 8:14 am)
[LAU] [LAA] [ANN] guitarix-0.04.6-1 release, hermann meyer, (Wed Jun 24, 3:03 pm)
Re: [LAU] [LAA] [ANN] guitarix-0.04.6-1 release, Dragan Noveski, (Wed Jun 24, 3:49 pm)
Re: [LAU] [LAA] [ANN] guitarix-0.04.6-1 release, hermann meyer, (Wed Jun 24, 4:22 pm)
[LAU] [ANN] guitarix-0.03.9-1 bugfix release, hermann meyer, (Thu Mar 26, 7:52 pm)
[LAU] [ANN] guitarix release version 0.03.8-1, hermann meyer, (Wed Mar 18, 7:00 pm)
[LAU] [ANN] guitarix third release, hermann meyer, (Sun Nov 23, 5:19 pm)
Re: [LAU] [ANN] guitarix third release, Dragan Noveski, (Tue Nov 25, 1:18 pm)
Re: [LAU] [ANN] guitarix third release, hermann meyer, (Tue Nov 25, 2:34 pm)
Re: [LAU] [ANN] guitarix third release, Dragan Noveski, (Wed Nov 26, 2:07 am)
[LAU] [ANN] guitarix second release, hermann meyer, (Sun Nov 2, 3:35 pm)
Re: [LAU] [ANN] guitarix second release, David Baron, (Sun Nov 2, 6:39 pm)
Re: [LAU] [ANN] guitarix second release, Fons Adriaensen, (Sun Nov 2, 8:18 pm)
Re: [LAU] [ANN] guitarix second release, hermann meyer, (Sun Nov 2, 6:52 pm)
Re: [LAU] [ANN] guitarix second release, Dragan Noveski, (Sun Nov 2, 4:41 pm)
Re: [LAU] [ANN] guitarix second release, hermann meyer, (Sun Nov 2, 4:58 pm)
Re: [LAU] [ANN] guitarix second release, Dragan Noveski, (Sun Nov 2, 5:44 pm)
Re: [LAU] [ANN] guitarix second release, Julien Claassen, (Sun Nov 2, 3:59 pm)
Re: [LAU] [ANN] guitarix second release, hermann meyer, (Sun Nov 2, 4:35 pm)
Re: [LAU] [ANN] guitarix second release, Julien Claassen, (Sun Nov 2, 6:30 pm)
Re: [LAU] [ANN] guitarix second release, Darren Landrum, (Sun Nov 2, 3:53 pm)
Re: [LAU] [ANN] guitarix second release, hermann meyer, (Sun Nov 2, 4:30 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Joern Nettingsmeier, (Fri Oct 17, 3:38 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Kjetil S. Matheussen, (Fri Oct 17, 3:01 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Olivier Guilyardi, (Fri Oct 17, 3:16 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Kjetil S. Matheussen, (Fri Oct 17, 3:31 pm)
Re: [LAU] Simple, easy multithreaded circular buffer library..., Kjetil S. Matheussen, (Fri Oct 17, 12:26 pm)