Question

Factors designating a piece of code as critical section

As of I understand, process synchronization is employed using kernel data structures such as semaphores, to prevent concurrent access to the critical section of the code. In general I see definitions to be, "critical section is the piece of code that may access shared data (or) shared resources". So the questions are:

  • Shared data is a user space entity. Hence it is the responsibility of the user process to ensure consistency of its access.
  • I presume that concurrent access to resources by multiple processes is something that the kernel should take care. What sort of user level synchronisations are required there?
  • What are the factors by which a piece of code in user space program is decided to be a critical section.
Was it helpful?

Solution

You are mixing "kernel space/user space" with "critical section".
Kernel/User space only defines what kind of privilege does a process possess. If a thread is executing in user space it cannot access the physical memory directly. It has to go through kernel's virtual memory management.
On the other hand, critical section is part of the code that if executed by two processes in parallel could result in data corruption. This would be happening because of the fact that the code is accessing some shared resource.
Those two concept are independent. Critical section can be either in user space or kernel space. Some kind of synchronization is needed inorder for avoiding the corruption of a shared resource. Even in the case where two process/thread are running in kernel mode and want to access a shared resource, they need to apply some sort of synchronization mechanism(spinlocks or mutex).

I hope this explains helps.

OTHER TIPS

Inter-process synchronization can be implemented by named synchronization objects. The Windws Synchronization Functions offer for example named mutexes and named semaphores. See this answer for Linux.

Shared resources of a number of processes may for example be shared memory.

Using the term critical section the way done in the question is a bit misleading since there are Critical Section Objects (Windows) dealing with thread synchronization.

I suspect you mean this more general since you explicitly note processes too.

However, any shared resource, be it shared memory or any other object shall be protected against concurrent access while being worked on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top