<Sound Dev> [12] Review Request: 8207150 Clip.isRunning() may return true after Clip.stop() was called

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Sat Aug 4 23:43:52 UTC 2018

On 03/08/2018 17:44, Phil Race wrote:
> I don't know what your notation for the race condition means. Please expand and explain in more detail how this happens and add it to the bug report as well as here.

Below some parts of the code which are executed when we play audio in 
write(...) and when we stop the playing.

>> The problem exists in our DirectAudioDevice implementation. Before we play the audio we have this check in write():
>> if (!isActive() && doIO) {
>>     setActive(true);
>>     setStarted(true);
>> }
>> And to stop the clip we have this:
>> synchronized(lock) {
>>     // need to set doIO to false before notifying the
>>     // read/write thread, that's why isStartedRunning()
>>     // cannot be used
>>     doIO = false;
>>     lock.notifyAll();
>> }
>> setActive(false);
>> setStarted(false);

>> Note that it is possible to get the next race.
>> 1 write() -> if(doIO) is true
>> 2 stop() -> doIO=false + setActive(false) + setStarted(false)
>> 3 write() -> setActive(true) + setStarted(true)

The notion above means:
(1) in the write method we execute "if(doIO)" when doIO is true.
(2) in the stop() method we set doIO to false and call
(3) in the write method we call:

So we stop play of audio at step (2) but the clip still reports itself 
as "running".

Best regards, Sergey.

More information about the sound-dev mailing list