Investigate possible data races in the sound system
Currently thread sanitizers generate many messages about data races in the sound system. An example of such race:
WARNING: ThreadSanitizer: data race (pid=29981)
Read of size 8 at 0x7b44000041f8 by thread T4 (mutexes: write M1409):
#0 MWSound::MovieAudioDecoder::getAudioClock() /home/andrei/Downloads/openmw/apps/openmw/mwsound/movieaudiofactory.cpp:63 (openmw+0x80716a)
#1 Video::MovieAudioDecoder::synchronize_audio() /home/andrei/Downloads/openmw/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp:144 (openmw+0xb44ec3)
#2 MWSound::OpenAL_SoundStream::refillQueue() /home/andrei/Downloads/openmw/apps/openmw/mwsound/openal_output.cpp:544 (openmw+0x7f3ebb)
#3 MWSound::OpenAL_SoundStream::process() /home/andrei/Downloads/openmw/apps/openmw/mwsound/openal_output.cpp:506 (openmw+0x7f3fb5)
#4 MWSound::OpenAL_Output::StreamThread::run() /home/andrei/Downloads/openmw/apps/openmw/mwsound/openal_output.cpp:342 (openmw+0x7ff5ae)
#5 OpenThreads::ThreadPrivateActions::StartThread(void*) <null> (libOpenThreads.so.21+0x5c84)
Previous write of size 8 at 0x7b44000041f8 by main thread:
#0 MWSound::MovieAudioFactory::createDecoder(Video::VideoState*) /home/andrei/Downloads/openmw/apps/openmw/mwsound/movieaudiofactory.cpp:169 (openmw+0x806bda)
#1 Video::VideoState::stream_open(int, AVFormatContext*) /home/andrei/Downloads/openmw/extern/osg-ffmpeg-videoplayer/videostate.cpp:590 (openmw+0xb428b6)
#2 MWGui::WindowManager::playVideo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/andrei/Downloads/openmw/apps/openmw/mwgui/windowmanagerimp.cpp:1822 (openmw+0x57a0a4)
#3 OMW::Engine::prepareEngine(Settings::Manager&) /home/andrei/Downloads/openmw/apps/openmw/engine.cpp:548 (openmw+0xb398fc)
#4 OMW::Engine::go() /home/andrei/Downloads/openmw/apps/openmw/engine.cpp:691 (openmw+0xb3e5b2)
#5 runApplication(int, char**) /home/andrei/Downloads/openmw/apps/openmw/main.cpp:260 (openmw+0xb233f7)
#6 wrapApplication(int (*)(int, char**), int, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/andrei/Downloads/openmw/components/debug/debugging.cpp:137 (openmw+0xc737fa)
#7 __libc_start_main ../csu/libc-start.c:308 (libc.so.6+0x2375a)
Both tsan and DRD tool for Valgrind report such issues.
I saw data races for at least these variables:
- MovieAudioDecoder::mAudioTrack
- Stream::mHandle
- OpenAL_SoundStream::mSource
I am not sure if there are real issues, or scanners are just too paranoid.
Edited by Andrei Kortunov