Switching between user-level and kernel-level threads
Exceptional Control Flow

There is a process called exceptional control flow to deal with the problem of switching between kernel code and user code. Switching between user mode programs actually need the kernel code being executed between.

Context Switching

When a user mode program times out, an external timer triggers an interrupt. Then the operating system kernel takes back the control, save all registers used by the program. Then schedule another program to run. 

Exceptions and Interrupts

There are some kinds of exceptional interrupts from outside, for instance user hit Ctrl-C or when you try to open a file (syscall), it will switch to kernel code. When the file is opened for you, the program will come back running. Another example is on modern virtual memory systems, if a memory requested is currently in a disk, not on memory, the system will interrupt the program by a page fault. Then the computer continue to run kernel code to fetch that portion of memory and come back to the program.