testatomic: destroy threads + free all memory at quit to fix --trackmem

This commit is contained in:
Anonymous Maarten
2024-05-13 16:05:55 +02:00
committed by Anonymous Maarten
parent eda9247f01
commit 831c79d32f

View File

@@ -128,7 +128,8 @@ static int SDLCALL adder(void *junk)
static void runAdder(void) static void runAdder(void)
{ {
Uint64 start, end; Uint64 start, end;
int T = NThreads; int i;
SDL_Thread *threads[NThreads];
start = SDL_GetTicksNS(); start = SDL_GetTicksNS();
@@ -136,14 +137,18 @@ static void runAdder(void)
SDL_AtomicSet(&threadsRunning, NThreads); SDL_AtomicSet(&threadsRunning, NThreads);
while (T--) { for (i = 0; i < NThreads; i++) {
SDL_CreateThread(adder, "Adder", NULL); threads[i] = SDL_CreateThread(adder, "Adder", NULL);
} }
while (SDL_AtomicGet(&threadsRunning) > 0) { while (SDL_AtomicGet(&threadsRunning) > 0) {
SDL_WaitSemaphore(threadDone); SDL_WaitSemaphore(threadDone);
} }
for (i = 0; i < NThreads; i++) {
SDL_WaitThread(threads[i], NULL);
}
SDL_DestroySemaphore(threadDone); SDL_DestroySemaphore(threadDone);
end = SDL_GetTicksNS(); end = SDL_GetTicksNS();
@@ -726,6 +731,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE); RunFIFOTest(SDL_FALSE);
#endif #endif
RunFIFOTest(SDL_TRUE); RunFIFOTest(SDL_TRUE);
SDL_Quit();
SDLTest_CommonDestroyState(state); SDLTest_CommonDestroyState(state);
return 0; return 0;
} }