Session 10 : Concurrency
Concurrency in software execution can occur at four different levels:
- Machine instruction level
- High-level language statement level
- Unit level
- Program level
Subprogram-Level Concurrency
* A task or process or thread is a program unit that can be in concurrent execution with other program units
* Tasks differ from ordinary subprograms in that:
- A task may be implicitly started
- When a program unit starts the execution of a task, it is not necessarily suspended
- When a task’s execution is completed, control may not return to the caller
* Tasks usually work together
Two General Categories of Tasks
* Heavyweight tasks execute in their own address space
* Lightweight tasks all run in the same address space – more efficient
* A task is disjoint if it does not communicate with or affect the execution of any other task in the program in any way
Task Synchronization
* A mechanism that controls the order in which tasks execute
* Two kinds of synchronization
- Cooperation synchronization
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoZxbarSKqKR2RKuC_dtnGYa0axyyBE-eefRxH6OB9B02VGASP8e2s7EOxFrvX_1czcMoTjzoNq_qKkp7A0z-sZKX9LCK_1IDze-r-6Q9gwCrt0P68BSLOrFlY0PCRC3FeW1xqMI5E68Y/s320/Picture1.png)
- Competition synchronization
* Task communication is necessary for synchronization, provided by:
- Shared nonlocal variables
- Parameters
- Message passing
Kinds of synchronization
* Cooperation: Task A must wait for task B to complete some specific activity before task A can continue its execution, e.g., the producer-consumer problem
* Competition: Two or more tasks must use some resource that cannot be simultaneously used, e.g., a shared counter
Scheduler
* Providing synchronization requires a mechanism for delaying task execution
* Task execution control is maintained by a program called the scheduler, which maps task execution onto available processors
Task Execution States
task can be in several different states :
* New - created but not yet started
* Ready - ready to run but not currently running (no available processor)
* Running
* Blocked - has been running, but cannot now continue (usually waiting for some event to occur)
* Dead - no longer active in any sense
Semaphores
* A semaphore is a data structure consisting of a counter and a queue for storing task descriptors
* A task descriptor is a data structure that stores all of the relevant information about the execution state of the task
* Semaphores can be used to implement guards on the code that accesses shared data structures
* Semaphores have only two operations, wait and release (originally called P and V by Dijkstra)
* Semaphores can be used to provide both competition and cooperation synchronization
Monitors => abstract data type for shared data
One solution to some of the problems of semaphores in a concurrent environment is to encapsulate shared data structures with their operations and hide their representations—that is, to make shared data structures abstract data types with some special restrictions. This solution can provide competition synchronization without semaphores by transferring responsibility for synchronization to the run-time system.
Rendezvous Time Lines
- Machine instruction level
- High-level language statement level
- Unit level
- Program level
Subprogram-Level Concurrency
* A task or process or thread is a program unit that can be in concurrent execution with other program units
* Tasks differ from ordinary subprograms in that:
- A task may be implicitly started
- When a program unit starts the execution of a task, it is not necessarily suspended
- When a task’s execution is completed, control may not return to the caller
* Tasks usually work together
Two General Categories of Tasks
* Heavyweight tasks execute in their own address space
* Lightweight tasks all run in the same address space – more efficient
* A task is disjoint if it does not communicate with or affect the execution of any other task in the program in any way
Task Synchronization
* A mechanism that controls the order in which tasks execute
* Two kinds of synchronization
- Cooperation synchronization
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoZxbarSKqKR2RKuC_dtnGYa0axyyBE-eefRxH6OB9B02VGASP8e2s7EOxFrvX_1czcMoTjzoNq_qKkp7A0z-sZKX9LCK_1IDze-r-6Q9gwCrt0P68BSLOrFlY0PCRC3FeW1xqMI5E68Y/s320/Picture1.png)
- Competition synchronization
* Task communication is necessary for synchronization, provided by:
- Shared nonlocal variables
- Parameters
- Message passing
Kinds of synchronization
* Cooperation: Task A must wait for task B to complete some specific activity before task A can continue its execution, e.g., the producer-consumer problem
* Competition: Two or more tasks must use some resource that cannot be simultaneously used, e.g., a shared counter
Scheduler
* Providing synchronization requires a mechanism for delaying task execution
* Task execution control is maintained by a program called the scheduler, which maps task execution onto available processors
Task Execution States
task can be in several different states :
* New - created but not yet started
* Ready - ready to run but not currently running (no available processor)
* Running
* Blocked - has been running, but cannot now continue (usually waiting for some event to occur)
* Dead - no longer active in any sense
Semaphores
* A semaphore is a data structure consisting of a counter and a queue for storing task descriptors
* A task descriptor is a data structure that stores all of the relevant information about the execution state of the task
* Semaphores can be used to implement guards on the code that accesses shared data structures
* Semaphores have only two operations, wait and release (originally called P and V by Dijkstra)
* Semaphores can be used to provide both competition and cooperation synchronization
Monitors => abstract data type for shared data
One solution to some of the problems of semaphores in a concurrent environment is to encapsulate shared data structures with their operations and hide their representations—that is, to make shared data structures abstract data types with some special restrictions. This solution can provide competition synchronization without semaphores by transferring responsibility for synchronization to the run-time system.
Rendezvous Time Lines
Komentar
Posting Komentar