Menu

#45 serious synchronization bug!

open
nobody
None
5
2015-07-30
2006-09-26
Anonymous
No

Hi,

I found a serious bug when a stream ends. Actually I
don't understand how no one else had any problems...
After hours of debugging I could finally fix it.

Here is the issue:
DSAudioDevice::update updates all running streams.
This action is synchronized with the scoped lock. If a
stream ends then m_device->fireStopEvent is called
inside DSOutputStream::update.
AbstractDevice::fireStopEvent creates an event with a
reference counted pointer to the stream (m_stream).
Then the event is forwarded to another thread
(m_events_available.notify() in
AbstractDevice::fireStopEvent). The other thread calls
the registered callbacks, where I set the stream to
NULL (in my application). Because the reference count
of the stream is currently 2 (the second reference
from the event) nothing happens except decreasing the
reference count to 1. When the first audiere thread
proceeds and the event instance goes out of scope (in
AbstractDevice::fireStopEvent) the second reference of
the stream is deleted, the reference counter is set to
0 and thus the destructor of the stream is called. In
DSOutputStream::~DSOutputStream the stream is removed
from the device. In DSAudioDevice::removeStream there
is a scoped lock, but this is useless since we are in
the same thread where the lock is first called
(DSAudioDevice::update). Now the stream is actually
deleted although we are still inside
DSOutputStream::update. When leaving this method the
scoped lock is deleted (because it goes out of scope).
But this crashes the application since the stream was
already deleted!

Keep in mind that this problem does not occur
everytime. It depends which thread is faster. e.g. in
which thread the reference count is first decreased to
1.

I hope my explanation was clear enough.
Simple solution to this issue:
change the reference counted pointer in the event
instance to a normal pointer. In class StopEventImpl
change "OutputStreamPtr m_stream" to "OutputStream *
m_stream".

btw, Audiere is great. I hope you can make it more
popular. Maybe you can install a Forum? the mailing
lists are quite hard to use (at least for me).

bye,
Alex

Discussion

  • Nobody/Anonymous

    Logged In: NO

    I have (maybe) same issue, especialy on machine
    with HyperThreading.
    Thanks Alex for your solution !

     
  • Chad Austin

    Chad Austin - 2007-04-15

    Logged In: YES
    user_id=7212
    Originator: NO

    Thank you, that was a very clear description. We might be working on a fix... (I don't think turning a smart pointer into a raw pointer is the right fix.)

     
  • Nobody/Anonymous

    Logged In: NO

    I also have this problem, but of my two computers, it only occurs on my dual-core laptop. It doesn't happen on my single-processor desktop.

     
  • John Barletti

    John Barletti - 2015-07-30

    Hello, I have the same problem on a 64-bit PC, but as a newbie I can't fix it manually. Where can I find a version of audiere.dll without that bug?

     

Log in to post a comment.

MongoDB Logo MongoDB