Several states of a thread

Source: Internet
Author: User

Threads generally can be divided into five states:

1> new state has just been created, not yet used, that is, the following code just ended the moment the state of the thread.

Nsthread *thread = [[Nsthread alloc] initwithtarget:self selector: @selector (run) Object:nil];

2> ready state: The thread system that you just created will do some work, and the thread will be joined to a pool of scheduled threads waiting to be used, when the thread is in the ready state.

3> running state: After [thread start], thread is running, the appropriate point is in the processing of tasks, such as downloading tasks, has been downloaded, no rest, and blocking the status of comparison

4> dead state: Thread task execution complete, or exception \ Force exit after the thread is destroyed! If the task is performed properly, the thread enters the scheduler pool.

At this point, if the system thread is not tense and there is no task waiting for the system to create the thread, then the system will move the thread out of the scheduled thread pool and the threads are destroyed.

If there are many tasks waiting to create a thread to process, then the system will not talk about threads removing the scheduler thread pool to destroy him, but directly let him perform the task.

The process of destroying this thread, and creating a new thread, is omitted.

5> blocking state: Call the Sleep method or add a mutex (synchronous lock),

Several states of a thread

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.