From 6ebc56939fde4607dd68990687e28968af4cfdb1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 17:19:22 +0100 Subject: [PATCH] Acquire mutex before modifying variable in wxSoundSyncOnlyAdaptor The mutex must be locked to avoid data races with the thread actually playing the sound. --- src/unix/sound.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index 394c786d66..20646f2d7e 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -386,14 +386,11 @@ void wxSoundSyncOnlyAdaptor::Stop() wxLogTrace(wxT("sound"), wxT("asking audio to stop")); #if wxUSE_THREADS + m_mutexRightToPlay.Lock(); + // tell the player thread (if running) to stop playback ASAP: m_status.m_stopRequested = true; - // acquire the mutex to be sure no sound is being played, then - // release it because we don't need it for anything (the effect of this - // is that calling thread will wait until playback thread reacts to - // our request to interrupt playback): - m_mutexRightToPlay.Lock(); m_mutexRightToPlay.Unlock(); wxLogTrace(wxT("sound"), wxT("audio was stopped")); #endif