Many times when trying to catch a bug , or to validate that your parallel code runs correctly you wish to run your code again and again and again until break on an assertion or even better until you persuade yourself that your code is good enough. Once more, stakoverflow has the answer for us:

set $n = 100
while $n-- > 0
  printf "starting program\n"
  run
  if $_siginfo
    printf "Received signal %d, stopping\n", $_siginfo.si_signo
    loop_break
  else
    printf "program exited\n"
  end
end

If you use it often save it in a file and launch it using

gdb --batch --command=<above script> --args <executable> <argument list>

source