Whenever your program stops
under GDB for any reason, all threads of execution stop, not just the current
thread. This allows you to examine the overall state of the program, including
switching between threads, without worrying that things may change underfoot.
Conversely, whenever you
restart the program, all threads start executing. This is true
even when single-stepping with commands like step
or next.
In particular, GDB cannot
single-step all threads in lockstep. Since thread scheduling is up to your
debugging targets operating system (not controlled by GDB), other threads
may execute more than one statement while the current thread completes
a single step. Moreover, in general other threads stop in the middle of
a statement, rather than at a clean statement boundary, when the program
stops.
You might even find your
program stopped in another thread after continuing or even single-stepping.
This happens whenever some other thread runs into a breakpoint, a signal,
or an exception before the first thread completes whatever you requested.