What Are Threads (What is a Thread)?

前端 未结 5 584
鱼传尺愫
鱼传尺愫 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条回答
  •  -上瘾入骨i
    2020-12-31 22:45

    An individual thread is so named because it is a single thread of execution through your code. If you have multiple threads then you have multiple threads of execution through your code simultaneously (or as simultaneously as your single/multicore system supports). Both threads have access to the same heap though use different stacks. This means data in your program may be visible by both threads and may be changed by either thread. This can of course lead to serious problems which requires protection against.

    It is worth noting that a thread is different to a process. A key difference is that two threads can access the same data (heap) while two processes cannot.

    For a more full description see other online descriptions

    wikipedia

提交回复
热议问题