D
D
Dmitry2015-11-15 22:33:17
Operating Systems
Dmitry, 2015-11-15 22:33:17

Where are the variables that processes access before entering the critical section stored?

I have a rather chaotic question today, gentlemen.
I am in the process of reading Tanenbaum's "Modern OS", in the section "Interaction of processes" the author discusses the method of achieving mutual exclusion of processes ( interrupt prohibition, blocking variables, strict interleaving ). If the idea of ​​disabling interrupts is more or less clear, then confusion begins with the use of variables.
Excerpt from the book:

As a second attempt, consider a software solution that uses
a single shared (blocking) variable whose initial value is zero. When
a process needs to enter its critical region, it first checks the value of the
blocking variable. If it is 0, the process sets it to 1 and enters
the critical region. If the value is already 1, the process simply waits until it
becomes zero. Thus, a value of zero indicates that none of the
processes is in its critical region, and a value of one indicates that some process
is in its critical region.

Please correct my line of reasoning. If we imagine two processes that are loaded into RAM and there is a certain critical area between them.
e2805513ca664bb7b985d141ee9c930f.png
As the author writes: If process 1 wants to work in the critical section, then it reads the value of the variable X for 0 or 1. And based on this, it enters its critical region, let's say X=0, then process 1 sets X=1 and starts its work.
But how can process 2 read the value of the X variable of the first process? Where should he read it from? If I understand correctly, the OS protects a process's memory from being invaded by other processes. It turns out process 2 cannot read someone else's address space of process 1.
Thank you in advance, colleagues

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Tsilyurik, 2015-11-16
@Ninjacoder

I am in the process of reading Tanenbaum's "Modern OS",

Do not read this book by E. Tanenbaum.
Consider everything related to synchronization only in POSIX (Linux), not in Windows (as long as you consider interactions within the limits of Windows, you will remain disabled).
You can look here: QNX/UNIX: Anatomy of Concurrency
There are scoped variables: local, global, file level, operating system level...
Your variable is shared between processes.

V
Vladimir Martyanov, 2015-11-15
@vilgeforce

Below we are talking about Windows.
Some terminology: CriticalSection is an object that can only be used within one process. Mutex is a named object and can be used to communicate between processes.
Further, there are special APIs for working with a section and Mutex, which hide implementation details, so there is no problem of access to a foreign process. A section can certainly be stored in the memory of its process: on the stack or in the "normal" address space.

R
rutaka nashimo, 2015-11-16
@rutaka_n

Alternatively, there may be shared memory between processes. It's about a simple situation.
If we talk about some complex resource, then it is controlled by the OS or the corresponding driver and the process asks the possibility of obtaining a resource from it through an API or a system call.
I hope I understood the question correctly and was able to answer it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question