lzl
lzl
驱动大牛
驱动大牛
  • 注册日期2001-09-11
  • 最后登录2010-06-22
  • 粉丝1
  • 关注0
  • 积分127分
  • 威望48点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
阅读:17313回复:4

请教版主 何谓线程上下文

楼主#
更多 发布于:2002-02-17 10:16
在看programming windows driver model
时,很多地方提到线程上下文,不知其为何物.
l=z=l 我听说,灌水是使分数快速增长的有效方法
jeosph
驱动中牛
驱动中牛
  • 注册日期2001-04-19
  • 最后登录2006-08-08
  • 粉丝0
  • 关注0
  • 积分96分
  • 威望11点
  • 贡献值0点
  • 好评度9点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-02-19 10:28
在看programming windows driver model
时,很多地方提到线程上下文,不知其为何物.


简单地说:就是和线程运行相关的一些状态,如寄存器,C,Z ,当然还有,内存。。。。。。。。
Tom.Cat
禁止发言
禁止发言
  • 注册日期2001-10-10
  • 最后登录2019-07-29
  • 粉丝1
  • 关注0
  • 积分-53792分
  • 威望197411点
  • 贡献值0点
  • 好评度5点
  • 原创分0分
  • 专家分0分
  • 社区居民
板凳#
发布于:2002-02-21 16:31
用户被禁言,该主题自动屏蔽!
Alexander
驱动大牛
驱动大牛
  • 注册日期2002-02-04
  • 最后登录2005-06-16
  • 粉丝0
  • 关注0
  • 积分-5分
  • 威望-1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-02-22 17:20
我的理解,还请版主指正:
Windows在一个特定的结构中保存一个线程的相关信息,如线程状态,CPU各寄存器的状态,及该线程属于哪个进程等。
所谓线程上下文,就是指这个结构。
Windows在进行线程切换时,就要先保存当前的线程状态,再将目标线程状态置为当前执行环境。
换句话说,就类似于8086中的DS,BP,SP,CS和IP等。


[编辑 -  2/23/02 作者: liuqun]
Alexander
驱动大牛
驱动大牛
  • 注册日期2002-02-04
  • 最后登录2005-06-16
  • 粉丝0
  • 关注0
  • 积分-5分
  • 威望-1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于: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.
游客

返回顶部