ThreadsProcess Interaction CONTENTS Threads Process interaction THREADS Process
- Slides: 56
Threads-Process Interaction
CONTENTS à Threads à Process interaction
THREADS
à Process image (program, data, stack, PCB) à Allocated resources: (open files, main memory, I/O devices, …) Address space of a process
à Process properties: distinguished address spaces (Unix) à The operations on processes and context switch are rather time consuming (overhead)
The concept of a process embodies two requirements: Resource ownership Resources can be allocated to processes, e. g. , memory, I/O devices…
Scheduling/execution A process has an execution state, a priority, and processes are the entities scheduled by the O. S.
the unit of dispatching is usually referred to as a thread or lighthweight process
the unit of resource ownership is usually still referred to as a process or a task
Multithreading: the ability of an O. S. to support multiple threads within a single process
All the threads of a process share in the same process address space and have access to the same data
Any thread has several associated entities: à A thread execution state (running, ready, . . ) à A saved thread context, when not in execution
One process one thread Multiple processes one thread per process One process multiple threads Multiple processes multiple threads per process
THREADS BENEFITS: It takes less time à to create and terminate a thread than a process à to switch between two threads within the same process
Threads enhance efficiency in communication, because threads within the same process share memory and files
THREAD IMPLEMENTATION User-level threads Thread management is in charge of the application and the kernel is not aware of thread existence
THREAD IMPLEMENTATION User-level threads A thread library is typically used, wich is a package of routines for thread management
The thread library contains code for: à creating and destroying threads à passing messages and data betweeen threads
The thread library contains code for: à scheduling thread execution and saving and restoring thread context
Disavantages of user-level threads When a thread executes a system call, all the threads within that process are blocked
Disavantages of user-level threads A multithreaded application cannot take advantage of multiprocessing
Kernel-level threads (NT, Linux) à The whole thread management is made by the O. S.
Kernel-level threads (NT, Linux) à There is no thread management code in the application area, but only a simple API to address to the kernel thread facility
The main disavantage of the this approach is that the switch between two threads within the same process requires a mode switch to the kernel
A multithreaded application can take advantage of multiprocessing
PROCESS INTERACTION
CONCURRENT PROCESSES Set of processes which execute simultaneously
CONCURRENT PROCESSES Two processes are concurrent if the first operation of one of them begins before the last operation of the other
CONCURRENT PROCESSES P 1 P 2 overlapping t P 2 P 1 interleaving P 2 t
CONCURRENT PROCESSES Independent processes: a set of processes is indipendent if each process of the set cannot affect or be affected by the others processes
Cooperating processes: a set of processes is cooperating if each of them can affect or be affected by any other process
à The result of the cooperation depends from race conditions of the processes à The behaviour of a set of cooperating processes is not reproducible
PROCESS INTERACTION Competition: behavior exibited in the use of common resources that cannot be used simultaneously (because of mutual exclusion)
PROCESS INTERACTION Cooperation: execution of a common activity obtained by the exchange of information (via communication)
MUTUAL EXCLUSION process A full 3 The file 4 can be 5 inserted in the 6 position 7 file A file B file C file D A and B intend to insert a file in the table 7 . . . process B empty
MUTUAL EXCLUSION process A 3 file A 4 file B 5 file C 6 file D 1 Following the reading of the value 7 by A, A is suspended 7. . . process B empty
MUTUAL EXCLUSION process A 3 file A 4 file B 5 file C 6 file D 7 file E process B . . . 8 2 B reads the value 7, inserts the file E and increases the value of the variable empty to 8 empty
MUTUAL EXCLUSION process A 3 file A 4 file B 5 file C 6 file D 7 file xxx 8 process B 3 A resumes its execution and inserts the file xxx in 7 (the previous value is deleted) empty
COMMUNICATION P 1 buffer P 2 produce message remove message enter message consume message
COMMUNICATION à Correct sequence of operations: enter - remove – enter remove- … à Incorrect sequence of operations: remove – enter - …
SYNCHRONIZATION In the previous examples, in order to obtain a correct system behaviour, . . .
SYNCHRONIZATION . . . it is necessary to impose timing constraints to the execution of the process operations
SYNCHRONIZATION constraints Competition: only one process at a time must access to a common resource (indirect or implicit synchronization)
SYNCHRONIZATION constraints Cooperation: the order of operations observed by producers and consumers on the buffer must follow a fixed policy, . . .
SYNCHRONIZATION constraints. . . such as an alternation schedule (direct or explicit synchronization)
PROCESS INTERACTION MODELS à global environment model à message passing model
GLOBAL ENVIRONMENT MODEL The process system may be considered as a set of processes and resources (objects)
GLOBAL ENVIRONMENT MODEL O 2 O 1 P 2 P 1 O 3 P 3 O 4 O 1, O 4 private res. competition O 2, O 3 common res. cooperation
Messagge passing model The process system may be considered as a set of processes, . . .
Messagge passing model. . . each of them working in a local environment, i. e. , not directly accessibile by other processes
Messagge passing model P 1 channel Pn P 2
Any type of interactions among processes (communication, synchronization) requires a message exchange
Resources are typically not directly accessibles to processes Any resource is associated to a specific server process
BUFFER P producer C consumer
à The producer cannot enter a message in the buffer, if the buffer is full à The consumer cannot remove a message from the buffer, if the buffer is empty
d = num. of entered messages e = num. of removed messages N = size of the buffer O d-e N
- Process and threads
- Process and threads
- Slidetodoc.com
- C11 thread
- Shared memory java
- Conventional representation of external screw thread
- Flexible flat material made by interlacing yarns
- Escalonador de processos
- Os threads
- Vinaya pitaka is a sacred text of
- Needle like threads of spongy bone
- Used to trim pieces of fabric the two handles are the same
- Golden thread model
- Priority donation pintos
- Posix threads in os
- Threads java
- Osteospermum white lightning
- Forum.unity.com/threads/game-over.54735
- /threads/ fiji
- Threads consume cpu in best possible manner
- Sockets and threads
- Posix threads
- Forum.unity.com/threads/game-over.54735
- Thread vs process
- Sequence diagram threads
- Threads cannot be implemented as a library
- Threads.h
- Theory of metal cutting mcq
- Cuda threads per block
- Threads cannot be implemented as a library
- The kernel is unaware of user threads
- Cuda synchronize threads
- Threads in distributed systems
- Ece threads
- What is thread in operating system
- Ece threads
- Chia 3 threads
- Threads vs processes
- Scheduler activations
- Pintos advanced scheduler
- Mission thread example
- Threads em java
- Os threads
- How is socialization a lifelong process
- Interaction design process
- Interaction design process
- Iatf 16949 process interaction map
- Is the lifelong process of social interaction
- Dewey's reflective thinking process
- The process of interaction design
- Hci chapter 5
- System implementation process under it interaction model
- Process of interaction design
- Interaction planning process
- Career portfolio definition
- Deep perineal pouch contents
- Febrile non hemolytic transfusion reaction