Programs are written to solve problems. To execute a program, the operating system creates a process for that program. A process executes a program. By default, a process executes in the user mode. A process may need to use resources, like the hard disk or the network connection, that are shared by all the processes in the system. Or, it might need to do some privileged operation like change its priority. In other words, it needs help from
someone, who has overall access for the system. Then by some mechanism, it goes into the kernel mode from the user mode to do such operations. One such operation is synchronization - both for processes and threads. Synchronization is done using semaphores. For more details, refer to the link, Semaphore Basics.