From 922171f793d2a21304e1621e6165bda00517aa05 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 1 Feb 2025 11:05:36 -0800
Subject: [PATCH] testatomic: destroy threads + free all memory at quit to fix
--trackmem
Fixes https://github.com/libsdl-org/sdl2-compat/issues/285
---
test/testatomic.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/test/testatomic.c b/test/testatomic.c
index 75325e0..fd80fd6 100644
--- a/test/testatomic.c
+++ b/test/testatomic.c
@@ -131,7 +131,8 @@ static int SDLCALL adder(void *junk)
static void runAdder(void)
{
Uint32 start, end;
- int T = NThreads;
+ int i;
+ SDL_Thread *threads[NThreads];
start = SDL_GetTicks();
@@ -139,14 +140,18 @@ static void runAdder(void)
SDL_AtomicSet(&threadsRunning, NThreads);
- while (T--) {
- SDL_CreateThread(adder, "Adder", NULL);
+ for (i = 0; i < NThreads; i++) {
+ threads[i] = SDL_CreateThread(adder, "Adder", NULL);
}
while (SDL_AtomicGet(&threadsRunning) > 0) {
SDL_SemWait(threadDone);
}
+ for (i = 0; i < NThreads; i++) {
+ SDL_WaitThread(threads[i], NULL);
+ }
+
SDL_DestroySemaphore(threadDone);
end = SDL_GetTicks();
@@ -733,6 +738,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
+ SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}