Processing of threads (1)

Source: Internet
Author: User
The operating system uses processes to separate the different applications that they are performing. A thread is the basic unit in which the operating system allocates processor time, and there can be multiple threads executing code at the same time in the process. Each thread maintains exception handlers, scheduling priorities, and a set of systems used to save the structure of the thread context before scheduling the thread. The thread context includes all the information needed to allow the thread to continue to execute seamlessly in the host process address space, including the thread's CPU register group and stack.
The. NET Framework further subdivides the operating system process into a lightweight managed child process, called an application domain, represented by System.AppDomain. One or more managed threads (represented by System.Threading.Thread) can run in one or any number of application domains in the same unmanaged process. Although each application domain is started with a single thread, code in the application domain can create additional application domains and additional threads. As a result, managed threads can move freely between application domains in the same unmanaged process, and you may have only one thread moving between several application domains.
By the way, AppDomain.
An application domain, represented by the AppDomain object, that provides quarantine, uninstall, and security boundaries for executing managed code. Multiple application domains can run in one process, but there is no one-to-one association between application domains and threads. Multiple threads can belong to an application domain, although a given thread is not limited to one application domain, but at any given time, the thread executes in an application domain. Application domains are created by using the CreateDomain method. The AppDomain instance is used to load and execute the assembly (Assembly). When AppDomain is no longer in use, you can uninstall it.
An operating system that supports preemptive multitasking can create effects that are executed concurrently by multiple threads in multiple processes. It does this by dividing the available processor time between threads that require processor time and by taking turns allocating processor time slices for each thread. The currently executing thread is suspended at the end of its time slice while another thread continues to run. When the system switches from one thread to another, it saves the thread context of the preempted thread and reloads the saved thread context of the next thread in the thread queue.
The length of the time slice depends on the operating system and the processor. Because each time slice is small, multiple threads appear to be executing at the same time even if there is only one processor. This is actually what happens in a multiprocessor system where the executable threads are distributed across multiple available processors.
When to use multiple threads
Software that requires user interaction must respond as quickly as possible to the user's activities in order to provide a rich and varied user experience. But at the same time it must perform the necessary calculations to present the data to the user as quickly as possible. If your application uses only one thread of execution, you can use asynchronous programming in combination with. NET remoting or XML Web services created using ASP.net, and use the processing time of other computers in addition to the processing time of your own computer. This improves responsiveness to the user and reduces the processing time of the application. If you are doing a lot of input/output work, you can also use I/O completion ports to increase the response speed of your application.

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.