Computer operating system notes (7)--thread of process management

Source: Internet
Author: User
Tags semaphore

Purpose and requirements
1) Mastering the basic concepts of threading
2) Understanding thread synchronization and communication
3) Understand how threads are implemented the basic concept of thread 1 Threading Introduction

The purpose of the introduction process is to enable multiple programs to execute concurrently, increasing resource utilization and system throughput.
The purpose of introducing threads is to reduce the time and space overhead of the program when executing concurrently, and to make the OS more concurrency.

Basic properties of the process:
1) A process is an independent unit in which a person can have resources.
2) The process is also a basic unit that can be dispatched and distributed independently.

A thread is an execution path to a process that contains a separate stack and CPU register state, each of which shares all the resources of the process it is affiliated with, including open files, page tables (and therefore the entire user State address space), signal identification and dynamically allocated memory, and so on.

In a multithreaded OS, typically a process consists of multiple threads, each of which takes advantage of the basic unit of the CPU and is the entity that spends the least overhead.

Comparison of threads and processes
Threads are part of a process (threads cannot exist alone), threads run in process space, each thread shares all the resources of the process it is affiliated with (the thread does not own the resource, the thread uses only the resources), and the threads resulting from the process exiting into the process are forced to exit and clear.

Scheduling Concurrency of own Resources System Overhead
Process Traditional basic unit Low Have High
Thread Unit High Use Low
2 properties of a thread

1) Lightweight entities (one entity for a process): basically, they do not own resources. There are only a few resources that are essential to ensure independent operation.
2) The basic unit of independent Dispatch and Dispatch: the basic unit in which the CPU is running.
3) Concurrent execution : the thread of the same process can execute concurrently, and threads in different processes can execute concurrently.
4) Share process Resources : basically do not own resources, use the resources of the owning process. 3 Status of thread running

1) Execution status : The thread is executing on the CPU.
2) ready State : Have all the resources needed to wait for the CPU to be idle.
3) blocking state : Some resources are missing, waiting for the resource to complete. 4 creation and termination of threads

In a multithreaded OS, when an application starts, typically only one thread (the initialization thread) is executing, and it can create several threads as needed.

When creating a new thread, you need to create a function (or system call) with a pedigree, and provide the appropriate parameters, and when the thread creation function finishes executing, it returns a thread identifier for later use.

Thread termination mode
1) Voluntary withdrawal
2) error or forced termination by another thread

When a thread is terminated and does not immediately release the freed resource , the resource is detached from other threads only after the other threads in the process have performed the detach function . 5 processes in the multi-threaded OS

In a multithreaded OS, a process is a basic unit of resources, usually a process that contains multiple threads and provides resources for them, but the process no longer acts as an executing entity.

The properties of the process at this time
1) as a unit of system resource allocation
2) can include multiple threads
3) The process is not an executing entity, but still has to perform the related state of the synchronization and communication of the second thread

In order to support different frequency interactions and varying degrees of parallelism, multiple synchronization mechanisms are often available in multi-threaded OS. 1 Mutual exclusion lock

A mechanism used to implement mutually exclusive access to resources between threads.
Lock (); Unlock ();
In order to reduce the chance of thread being blocked, some systems also provide an operation command Trylock () on the mutex. 2 Condition Variables

Conditional variables are typically used with mutexes. Mutexes are used for short-term locking , which is used primarily to guarantee mutual exclusion of critical sections, while conditional variables are used for long waits for threads until the resources they wait for become available. 3 semaphore mechanism

1) Private semaphore : Enables synchronization between threads within the same process.
2) Common semaphores : Also known as System semaphores, to enable synchronization between threads in different processes or processes. How to implement a three-wire process 1 Kernel support thread (kernel-supported Threads)

For a typical process, whether it is a system process or a user process, the creation , revocation , and I/O operations required by the system device are entered into the kernel using system calls, which are then done by the appropriate handlers in the kernel. We say they run under the support of the operating system kernel.

Kernel support threads also rely on kernel support to run, thread creation and revocation also rely on the kernel, in addition to the kernel space for each kernel support thread set a thread control block, the kernel is based on the control block aware of the existence of a thread and control it. Windows NT and OS/2 support kernel threads.

Kernel Maintenance processes and threads
Advantages :
1) A thread initiates a system call that is blocked and does not affect the operation of other threads;
2) Time slices are allocated to threads, so multithreaded processes get more CPU time.

disadvantage : User thread mode switching overhead is large. 2 User-level threads (User-level Threads)

Instead of relying on the OS core, the application process uses line libraries to provide functions to create, synchronize, schedule, and manage threads to control user threads.

such as: Database system Informix, graphics processing PageMaker.

The maintenance of threads is done by the application process, and the kernel does not understand the existence of user-level threads.

Advantages :
Scheduling, switching is carried out within the application software, usually with simple rules, and no user-state/kernel mindset switching , so fast.

Disadvantages :
1) When a thread initiates a system call and blocks, the entire process waits;
2) Time slices are allocated to processes, and threads are slower per thread.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.