Process and multithreading, deadlock preliminary understanding

Source: Internet
Author: User

concept : A process is an execution activity on a computer, a dynamic execution of a program, a unit of resource allocation for an operating system, and a process that starts when a program is run. process can access processes on a local or remote computer, and can start and terminate processes in the Local system (System.Diagnostics)

A thread is the basic unit of processor time allocated by the operating system, and multiple operating systems look like simultaneous occurrences (system.threading)

Multi-Threading Advantages: 1. Background actions can also be performed when the user interface responds 2. Perform tasks by Priority 3. Connect to a Web server or database over a network

Multithreading Disadvantages: 1. Overloading the system may result in a performance decrease of 2. It is difficult to control multithreaded code, which can lead to many bugs

multithreading : A thread is a single sequential control flow in a program, and a thread is an entity in a process. A process can have multiple threads, and a thread must have a parent thread. Threads do not own system resources, only some data structures that must be run. It shares all of the resources owned by the process with other threads of the parent thread. Threads can create revocation, which implements concurrent execution of programs

Deadlock: A deadlock is a situation in which two or more threads that use a shared resource occupy some shared resources and wait for the resources that other threads occupy to occur, causing two or more threads to wait for each other to release resources and stop executing.

Example :

To start a thread:

The construction method uses the ThreadStart proxy as the parameter; the method that the ThreadStart points to is executed in the thread; The threads are started by the Start method.
Thread t = new Thread (new ThreadStart (Myclass.astaticmethod));
T.start ();
Properties and parameters for the thread:

Thread.Name Gets or sets the thread name; thread.priority Gets or sets the thread priority; Thread.IsBackground thread can run in the background
Managing Threads:
Thread.Sleep Blocking Current thread thread.sleep (3000); Blocks for 3 seconds

Suspend and resume are not commonly used to cause serious problems with applications such as deadlocks

Thread.Join wait for other threads to stop t.join (); Wait for the thread to exit
Thread.waithandle waits for one or more events WaitHandle.WaitAll (waitevents);

Thread.threadstate Properties--thread state

Break and End Threads:

Thread.Interrupt method interrupts the thread in the execution state; Thread.Abort method ends the thread run

  

Process and multithreading, deadlock preliminary understanding

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.