GNU GDB's Pedro Alves:

One thing I asked myself was, if gnu-nat.c couldn't be using the port's id as thread ids instead of a locally auto-generated number. Maybe the thread id of the main thread would be preserved across execs this way

Also see thread numbering of ps and GDB.

attach to a multi-threaded process. See threads 1 to 5. detach. attach again -- thread numbers continue where they stopped last time: now they're threads 6 to 10.