1

I programm C in VS Code with the gcc/gdb compiler/dubugger and SDL2. What happens is, that when I create threads via SDL2_CreateThread the debugger seems to hold before finishing the programm.

create threads like:

//doing this every frame
int THREADN  = 20;
SDL_Thread *treds[THREADN];

for(int i = 0; i < THREADN; i++)
   treds[i] = SDL_CreateThread(someFunc, "Timstred", NULL); //someFunc doesnt even have to do anything

for(int i = 0; i < THREADN; i++)
    SDL_WaitThread(treds[i], NULL);

The last two lines of my main function are:

printf("hello");
return 0; // return of main function

In VS Code terminal it prints hello but doesnt finish:

enter image description here

with finish i mean until it return to my directory command line thing:

enter image description here

normally I wouldnt have bothered about this, cause it normally takes like 3 sec to finish, but it actually depends on how long the programm was running and how many threads are used. If i use 20 threads and let it run for a few minute it takes really long like 30 seconds to finish. If I start the programm without the debugger it instantly finishes when i close it. I am just worried that the debugger has to clean up a mess that i left with my threads or somthing.

Tim Metz
  • 23
  • 6
  • You may install WSL or go for Dual-boot and use Valgrind (Or see this https://stackoverflow.com/q/413477/12845048). In general running at debug takes more time probably it is about memory copying etc. But I am not sure. I think you should not care if it is take more time in debugging since your program will not work in debug mode. – Savrona Jul 30 '21 at 10:52
  • 4
    Can you make a short program that we can compile as is to reproduce? See [mcve]. – HolyBlackCat Jul 30 '21 at 14:25

0 Answers0