Content
Concurrency
Concurrency is a property of systems in which the processes of a computation are done simultaneously, and can interact with each other
Computing models on which concurrent processes can run:
- Multiprogramación with a single processor
- Multiprocessor
- Distributed processing
It affects a large number of operating system design issues:
- Communication between processes
- Sharing and competition for resources
- Synchronization of the execution of several processes
- Allocation of processor time to processes/li>
Interaction between the processes
Types of processes:
- Independent
- Cooperating
Interaction between processes:
- Processes share or compete for access to physical or logical resources (including independent processes)
- Processes communicate and synchronize among themselves to achieve a common goal
Competition among processes for resources
The main control problem is the need for mutual exclusion. While a process is; using a share should not be allowed access to other processes
Making mutex compliance creates two additional issues:
- Deadlock
- Starvation
Classic problems of communication and synchronization
- The problem of the critical section
- The problem of the producer-consumer
- The problem of readers-writers
- Client-server communication
The problem of the critical section
We have no concurrent processes, which can be independent or cooperative
The critical section, each process has a fragment of code from which you are accessing some shared resource
When one process is running in its critical section, no one else can run on yours
Example of critical section
Two processes P_1 and P_2 share variables a and b. Variables meet the relationship a = b
Consider the following concurrent execution:
At the end of the execution no longer comply with the condition a = b
The solution is to use mutual exclusion when entering the critical sections
It is necessary to use some synchronization mechanism:
Requirements that any solution must offer:
- Mutual exclusion
- To avoid deadlocks
- Limited Wait: avoid starvation
The problem of the producer-consumer
One or more producers generate data and put them in a buffer
A single consumer takes items from the buffer one-by-one
Only one producer or consumer may access the buffer at a given instant
Example of producer-consumer
The problem of readers-writers
Any number of readers can read the file simultaneously
You can only write to the file by a writer in every moment
If a writer is accessing the file, no reader can read it
Example of readers-writers
Client-server communication
The server processes offer a number of services to other processes and clients
The process server can reside on the same machine as the client or in a different
Example of client-server
Communication mechanisms
- Files
- Variables in shared memory
- Pipes
- Nameless: pipes
- Named: FIFOS
- Message passing
Synchronization mechanisms
- Signals
- Pipes
- Nameless: pipes
- Named: FIFOS
- Traffic lights
- Monitors and variables conditional
- Message passing
Pipes
Mechanism of communication and synchronization
A pipeline or pipe is a data structure that is implemented in the kernel of the operating system for communication between address spaces
Can only be used between processes that are inherited through the call
Unnamed pipes: pipes
They use a FIFO buffer with a one-way data flow. They have one read endpoint and one write endpoint treated using file descriptors:
- Writing: put data in the pipe
- Reading: extract data from the pipe
Services POSIX pipes
Create a pipe without a name
Pipe Read File Descriptor:
File Descriptor to write to the pipe
Close the end of a pipe
Descriptor of file to close
To read from a pipe
Arguments use fd pipe read file descriptor, variable buffer where read data is stored, and nb maximum number of bytes to read
If the pipe is empty, the reading process is blocked until some process enters data
If the pipe is not empty, the call returns the number of bytes read and removes the requested data from the pipe
Write on a pipe
Arguments use fd pipe write file descriptor, variable buffer where data to be written is stored, and nb maximum number of bytes to write
If the pipe fills up, the writer process is blocked until it can be completed
The read and write operations are performed atomically
Create a named pipe
There is No need to inherit it via fork
To open a named pipe
Deleting a named pipe
Read, write, and close a FIFO, just like pipes, by: