From 831c79d32f44b536a6f8973e67be4a204783b36a Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 13 May 2024 16:05:55 +0200
Subject: [PATCH] testatomic: destroy threads + free all memory at quit to fix
--trackmem
---
test/testatomic.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/test/testatomic.c b/test/testatomic.c
index d82559ad3f59a..a6266859f73cb 100644
--- a/test/testatomic.c
+++ b/test/testatomic.c
@@ -128,7 +128,8 @@ static int SDLCALL adder(void *junk)
static void runAdder(void)
{
Uint64 start, end;
- int T = NThreads;
+ int i;
+ SDL_Thread *threads[NThreads];
start = SDL_GetTicksNS();
@@ -136,14 +137,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_WaitSemaphore(threadDone);
}
+ for (i = 0; i < NThreads; i++) {
+ SDL_WaitThread(threads[i], NULL);
+ }
+
SDL_DestroySemaphore(threadDone);
end = SDL_GetTicksNS();
@@ -726,6 +731,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
+ SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;
}