阅读:17369回复:4
请教版主 何谓线程上下文
在看programming windows driver model
时,很多地方提到线程上下文,不知其为何物. |
|
|
沙发#
发布于:2002-02-19 10:28
在看programming windows driver model 简单地说:就是和线程运行相关的一些状态,如寄存器,C,Z ,当然还有,内存。。。。。。。。 |
|
板凳#
发布于:2002-02-21 16:31
用户被禁言,该主题自动屏蔽! |
|
地板#
发布于:2002-02-22 17:20
我的理解,还请版主指正:
Windows在一个特定的结构中保存一个线程的相关信息,如线程状态,CPU各寄存器的状态,及该线程属于哪个进程等。 所谓线程上下文,就是指这个结构。 Windows在进行线程切换时,就要先保存当前的线程状态,再将目标线程状态置为当前执行环境。 换句话说,就类似于8086中的DS,BP,SP,CS和IP等。 [编辑 - 2/23/02 作者: liuqun] |
|
地下室#
发布于:2002-02-23 08:45
Like processes, every thread is represented internally in KERNEL32.DLL
by a block of memory allocated from the shared KERNEL32 heap. This memory block holds all the information KERNEL32 needs to maintain for a thread. (Actually, the block contains a few pointers to information outside the block, but you get the idea.) This memory block is called a thread database (TDB) in this book. (Note that, at different times, Microsoft has used TDB to mean Task Database and Thread Database.) As with process databases, a thread database is a KERNEL32 object. Its first DWORD contains the value 6, branding the block as a K32OBJ_THREAD object. If you\'re an advanced programmer who\'s poked around in the DDK or used WDEB386 or Softlce/W, you may have encountered another thread-related data structure called a THCB (Thread Control Block). THCBs are the ring 0 representation of threads. In Windows 95, threads are represented by separate ring 0 and ring 3 data structures. The ring 0 components, such as VMM.VXD, work with threads primarily via thread control blocks. The ring 3 components, such as KERNEL32.DLL, primarily use the thread database that I\'ll discuss in the upcoming section called \"The Thread Database.\" This chapter describes ring 3 thread behavior and mechanics, and doesn\'t attempt to cover the ring 0 side of threads. Although processes are the primary K32 object that owns things, threads also own (or are associated with) certain items. The first thing that springs to mind when asked, \"What would a thread own?\" is a register set. As I mentioned earlier, at any given time a thread is either executing or not exe-cuting (pretty obvious, huh?). When a thread is executing, its register set is stored in the CPU\'s registers. That is, the thread\'s EIP value is the value in the EIP register. When a thread isn\'t executing, its registers need to be stored off into memory somewhere. Therefore, each thread has a pointer to a memory buffer where the thread\'s register values are stored when it\'s not executing. Another thing every thread is associated with is a process. All the threads in a process share access to the things that a process owns. For instance, a process owns a memory context and has a private address space. All the threads in the process run in the same address space. A process also has a handle table for referring to files, events, consoles, memory mapped files, and so on. All threads in the process share the same handle values. For example, if handle value 3 refers to a memory mapped file, any thread in the process can use handle value 3 to refer to that memory mapped file. Threads also own many other things. Each thread has its own stack area, its own window message queue, its own set of Thread Local Storage values, and its own structured exception handling chain. In addition, a thread also acquires and releases ownership of the various synchronization objects that the thread uses during its execution. |
|