FIT2100 Lecture Notes - Lecture 5: Actor Model And Process Calculi, System Call, Code Segment

99 views7 pages
Lecture 4&5/Tute 5 - Threads & Concurrency
Threads
-The unit of dispatching for execution is referred to as
-Thread or Lightweight process
-The unit of resource ownership is referred to as
-Process or Task
-Multithreading: the ability of an OS to support multiple concurrent paths of execution within a
single process
-For an OS that supports threads, scheduling and dispatching is done on a thread basis
-Most of the state information dealing with execution is maintained in thread-level data
structures:
-Suspending a process involves suspending all threads of a process
-Termination of a process terminates all threads within the process
* All threads within a process share the same address space
Threads within a Process:
-Different parts of a program may do different things and they can be executed concurrently to
improve response time
-If there is an interaction between different parts of the programs, then concurrency control
needs to be applied
*each thread can be thought of a lightweight process and hence can be in different states
Attributes of Threads:
-An execution state (e.g. Running, Ready, etc.)
-Saved thread context when not running
-An execution stack
-Some per-thread static storage for local variables
-Access to the memory and resource of its process
Benefits of Threads:
-Takes less time create anew thread than a process
-Less time to terminate a thread than a process
-Switching between two threads takes less time than switching between processes
-Threads enhance efficiency in communication between programs
Thread States:
Key states: Running, Ready, Blocked
State Transition (change): Spawn (new threads), Block (wait for an event), Unlock (A blocked event
occurs — move the thread to the ready queue), Finish
Thread Synchronisation:
-It is necessary to synchronise the activities of various threads
-All threads of a process share the same address space and other system resources
-Any alteration of a resource by one thread affects the other threads in the same process
User-Level Thread (UTL) & Kernel-Level Thread (KLT)
ULT:
-All thread management is done by the application
-The kernel is not aware of the existence of threads
-Any application can be programmed to be multi-threaded by using a threads library (creating/
destroying threads, passing data between threads, scheduling threads execution, saving/
restoring thread contexts)
ULT: Advantages
-Thread switching does not require kernel mode privileges
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in
-Scheduling can be application specific
-ULTs can run on any OS
ULT: Disadvantages
-In a typical OS, many system calls are blocking
-When a ULT executes a system call, not only is that thread blocked, but all of the threads within
the process are also blocked
-In a pure ULT strategy, a multi-threaded application cannot take the full advantage of
multiprocessing
KLT:
-Thread management is done by the kernel
-No thread management is done by the application — through API to the kernel thread facility
-E.g: Windows
KLT: Advantages
-The kernel can simultaneously schedule multiple threads from the same process on multiple
processors
-If one thread in a process is blocked, the kernel can schedule another thread of the same
process
-The kernel routines can also be multi-threaded
KLT: Disadvantages
-The transfer of control from one thread to another thread within the same process requires a
mode switch to the kernel
Combined Approaches
-Thread creation is done in the user space
-Bulk of scheduling and synchronisation of threads are by the application
-Multiple ULTs from a single application is mapped onto smaller (or equal) number of KLTs
Threads:Processes
-1:1 — each thread of execution is a unique process with its own address space and resource
(e.g. Traditional UNIX implementations)
-M:1 — a process defines an address space and dynamic resource ownership, multiple threads
may be created and executed within that process (e.g. Windows NT, Linux, Solaris)
-1:M — a thread may migrate from one process environment to another, this allows a thread to
be easily moved among distinct systems (e.g. Emerald, Ra(Clouds))
-M:N — combines attributes of M:1 and 1:M cases (e.g. TRIX)
Unix/Linux System Managing Threads
A process (or task) in Linux is represented by a task_struct data structure — This structure contains
information in a number of categories
Linux: Threads:
-Linux does not recognise a distinction between threads and processes
-User-level threads are mapped into kernel-level processes
-A new process is created by copying the attributes of the current process
-The new process can be cloned so that it shares resources
-The clone() call creates separate stack spaces for each process
Linux: Namespaces
-A namespace enables a process to have a different view of the system than other processes
that have other associated namespaces
-One of the overall goals to support the implementation of control groups (cgroups <— virtual
machine)
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in

Document Summary

The unit of dispatching for execution is referred to as. The unit of resource ownership is referred to as. Multithreading: the ability of an os to support multiple concurrent paths of execution within a single process. For an os that supports threads, scheduling and dispatching is done on a thread basis. Most of the state information dealing with execution is maintained in thread-level data structures: Suspending a process involves suspending all threads of a process. Termination of a process terminates all threads within the process. * all threads within a process share the same address space. Different parts of a program may do different things and they can be executed concurrently to improve response time. If there is an interaction between different parts of the programs, then concurrency control needs to be applied. * each thread can be thought of a lightweight process and hence can be in different states. An execution state (e. g. running, ready, etc. )

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents