Re: [linux-audio-dev] Re: desktop and multimedia as an afterthought?

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Re: desktop and multimedia as an afterthought?
From: Benno Senoner (sbenno_AT_gardena.net)
Date: Tue Jul 13 2004 - 16:03:47 EEST


Martijn Sipkema wrote:

>It is often heard in the Linux audio community that mutexes are not realtime
>safe and a lock-free ringbuffer should be used instead. Using such a lock-free
>ringbuffer requires non-standard atomic integer operations and does not
>guarantee memory synchronization (and should probably not perform
>significantly better than a decent mutex implementation) and is thus not
>portable.
>
>

Why not portable ? on x86 you have guaranteed atomicity of 32bit
read/writes and using the read_ptr / write_ptr
approach guarantees that you will never get bad values for the
ringbuffer pointers. The worst that could happen
is that the reader reads an "old" value and thus getting a bit smaller
available read space from the ringbuffer but
given the asynchronous nature of multithreaded apps this is completely
meaningless.
(the audio thread does not know/care when then disk thread writes data
into the ringbuffer)
PPC guarantees 32bit atomicity too so the atomic macros we are using in
LinuxSampler simply translate to a load or a store on
both x86 and PPC and if future CPUs with non atomic access arise , just
add the macro in atomic.h.
I would not call that "non portable". posix mutexes are not portable
because they don't work on win32 so in general
applications with a certain complexity always require some platform
dependent code (either OS or CPU dependent) to
be portable on that platform. If you design your app decently the amount
of platform dependent code is really tiny , usually
 well below 1%.
About performance, nothing can beat lock free ringbuffers because it's
simply a few machine instructions that access
a read_ptr, write_ptr and return the address of the object you want to
read/write.

cheers,
Benno
http://www.linuxsampler.org


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Tue Jul 13 2004 - 16:10:16 EEST