What Are Threads (What is a Thread)?

前端 未结 5 583
鱼传尺愫
鱼传尺愫 2020-12-31 21:48

I\'m always confused about thread concepts. I haven\'t a chance to use them in a real environment so far. It would be helpful if someone could explain threads for me.

5条回答
  •  离开以前
    2020-12-31 22:44

    At the risk of oversimplifying:

    A thread is a line of execution through a program.

    In your basic programming model, the computer simply traces through your program one statement at a time, and at any given time, only one statement is being excecuted. If your program branches or calls another routine, execution will leave the place where control transferred and begin executing at another place, but still, only one thing is being done at any one time.

    With threads, multiple lines of control can be executing at the same time. For example, one part of your program can be interacting with the user, while another part is downloading a file in the background. Multi-threaded programs are much harder to program and it's much harder to envisage how they work.

提交回复
热议问题