# SDL: audio: More tweaking of \`device-\>thread\_alive\`

**URL:** <https://discourse.libsdl.org/t/sdl-audio-more-tweaking-of-device-thread-alive/45282>\
**Category:** SDL Commits\
**Created:** [August 4, 2023, 1:34am UTC](https://discourse.libsdl.org/t/sdl-audio-more-tweaking-of-device-thread-alive/45282 "2023-08-04T01:34:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [August 4, 2023, 1:34am UTC](https://discourse.libsdl.org/t/sdl-audio-more-tweaking-of-device-thread-alive/45282/1 "2023-08-04T01:34:04Z")

</div>

[https://github.com/libsdl-org/SDL/commit/0999a090a7d5b51e2cf950f5819045f84a159cdf](https://github.com/libsdl-org/SDL/commit/0999a090a7d5b51e2cf950f5819045f84a159cdf)

```diff
From 0999a090a7d5b51e2cf950f5819045f84a159cdf Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 4 Jul 2023 17:27:17 -0400
Subject: [PATCH] audio: More tweaking of `device->thread_alive`

---
 src/audio/SDL_audio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 342024b791e2..aea09ff80767 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -668,6 +668,7 @@ void SDL_AudioThreadFinalize(SDL_AudioDevice *device)
         if (device->thread) {
             SDL_DetachThread(device->thread); // no one is waiting for us, just detach ourselves.
             device->thread = NULL;
+ SDL_AtomicSet(&device->thread_alive, 0);
         }
         DestroyPhysicalAudioDevice(device);
     }
@@ -1085,6 +1086,7 @@ static void ClosePhysicalAudioDevice(SDL_AudioDevice *device)
             SDL_WaitThread(device->thread, NULL);
             device->thread = NULL;
         }
+ SDL_AtomicSet(&device->thread_alive, 0);
     }
 
     if (device->is_opened) {

```
