Thread in depth 1: The basic

Every single thread has the follow elements:

  1. Execution Context:Every thread has a execution context which maintains some basical data about the running of the thread, like windows identity information, pricipal ,etc.One important thing about execution context is,when a thread create another thread (say,to do some work asynchronously), the execution context will "flow" from main thread to the sub-thread to let it run just like the main thread do.You can say that a "execution context inherit". You can stop this by calling the System.Threading.ExecutionContext.SuppressFlow() static method, that will help improve the performance.
  2. Thread Kernel Object:TKO is a data structure.Everytime when a thread is created,a TKO will be assigned and initialized.TKO maintains a property of descriping the thread, and thread context.
  3. Thread Environment Block,which is related to exception.
  4. User-Mode Stack: this stack stores the local variables and arguments in the method,and the returnning address of the method,so the thread can move on from this address when returned from the method.
  5. Kernel-Mode Stack:a stack which managed by OS kernel function.
  6. Thread context switch causes a bad performence.Here is how a context switch work :OS will move the data on CPU's register to the current thread's context, then move the target thread's context data into the cpu register so that the cpu can do its work.

 

posted on 2017-04-18 00:28  wyman25  阅读(258)  评论(0编辑  收藏  举报

导航