设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> 游戏开发 >> 《Windows游戏编程大师技巧》(第二版)第11章
精品推荐
游戏开发点击TOP10
·DirectX5.0最新游戏编程指南 DirectDraw教程篇 二、第一个DirectDraw实例
·用Excel编写小游戏
·五子棋的原代码
·游戏开发方面相关的电子书下载
·游戏文件系统的解决方案
·基于LOD的大规模真实感室外场景实时渲染技术的初步研究 part II&III
·用MFC构造DirectX应用框架
·游戏开发开门
·《Windows游戏编程大师技巧》(第二版)第11章
·DirectX8.1的DirectDraw7研究手记(三)
编程开发点击TOP10
·数字小键盘指法练习
·ASP.NET 程序中常用的三十三种代码
·用C语言编通讯录程序(初学者级别的)
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

《Windows游戏编程大师技巧》(第二版)第11章

作者: 来源:网络文章 时间:2005-12-17 22:39:07

《Windows游戏编程大师技巧》(第二版)第11章(31) Get ready for the most confusing explanation you've ever heard… but it's not my fault, really! Whenever any thread terminates, it becomes signaled to the kernel, and when it is running, it is unsignaled. Whatever that means. And what is the price of plastic zippers tomorrow? You don't care! But what you do care about is how to test for the signaling.
我们知道,任何线程结束时都会向内核发出信号(Signaled),而它们运行时不会发出信号(Unsignaled)。需要了解的是如何监测这些信号。
可以使用Wait*()函数族来实现事件监测,该类函数可以实现单信号或多信号的侦测。此外,你可以调用其中一个Wait*()函数来等待,直到信号产生。这样做就可以避免使用忙循环。在绝大多数情况下,这样做要远优于轮询全局变量的方法。图11-21示意了Wait*()函数的工作机制以及与运行程序和OS内核间的关系。
图11-21:使用Wait*()函数的信号时间关系
 
需要使用的两个函数分别是WaitForSingleObject()和WaitForMultipleObjects()。这两个函数分别用于单信号和多信号侦测。它们的定义如下:
DWORD WaitForSingleObject(HANDLE  hHandle,    // handle of object to wait for
            DWORD  dwMilliseconds );    // time-out interval in milliseconds
hHandle用于确定对象。
dwMilliseconds定义超时时间,以毫秒为单位。如果该段时间间隔已经过去,即使侦测对象无信号也要返回。如果dwMilliseconds值为0,函数就立刻测读对象的状态并返回。如果其值为无限大,则函数永不超时。
If the function succeeds, the return value indicates the event that caused the function to return. If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError().
如果该函数执行成功,其返回值包含返回的条件状态。如果该函数执行失败,返回值是WAIT_FAILED。调用函数GetLastError()可以获得详细的出错信息。
该函数的成功返回值有以下几种:
• WAIT_ABANDONED——所指定的对象是一个互斥对象,该对象在所属线程结束前不能被线程释放。互斥对象的所有权被授予调用线程,互斥对象被设置为无信号。
• WAIT_OBJECT_0——指定对象的状态是有信号的。
• WAIT_TIMEOUT——超时时间已过,对象的状态是无信号的。
一般说来,WaitForSingleObject()函数检查指定对象的当前状态。如果对象无信号,调用线程就进入一种很有效率的等待状态。在此期间,该线程只占用极少的CPU时间,直到它等待的条件之一得到满足才结束等待。下面是多信号侦测函数,主要用于终止多个线程:
DWORD WaitForMultipleObjects(DWORD  nCount, // number of handles
                                            // in handle array

1.《Windows游戏编程大师技巧》(第二版)第11章(1)
2.《Windows游戏编程大师技巧》(第二版)第11章(2)
3.《Windows游戏编程大师技巧》(第二版)第11章(3)
4.《Windows游戏编程大师技巧》(第二版)第11章(4)
5.《Windows游戏编程大师技巧》(第二版)第11章(5)
6.《Windows游戏编程大师技巧》(第二版)第11章(6)
7.《Windows游戏编程大师技巧》(第二版)第11章(7)
8.《Windows游戏编程大师技巧》(第二版)第11章(8)
9.《Windows游戏编程大师技巧》(第二版)第11章(9)
10.《Windows游戏编程大师技巧》(第二版)第11章(10)
11.《Windows游戏编程大师技巧》(第二版)第11章(11)
12.《Windows游戏编程大师技巧》(第二版)第11章(12)
13.《Windows游戏编程大师技巧》(第二版)第11章(13)
14.《Windows游戏编程大师技巧》(第二版)第11章(14)
15.《Windows游戏编程大师技巧》(第二版)第11章(15)
16.《Windows游戏编程大师技巧》(第二版)第11章(16)
17.《Windows游戏编程大师技巧》(第二版)第11章(17)
18.《Windows游戏编程大师技巧》(第二版)第11章(18)
19.《Windows游戏编程大师技巧》(第二版)第11章(19)
20.《Windows游戏编程大师技巧》(第二版)第11章(20)
21.《Windows游戏编程大师技巧》(第二版)第11章(21)
22.《Windows游戏编程大师技巧》(第二版)第11章(22)
23.《Windows游戏编程大师技巧》(第二版)第11章(23)
24.《Windows游戏编程大师技巧》(第二版)第11章(24)
25.《Windows游戏编程大师技巧》(第二版)第11章(25)
26.《Windows游戏编程大师技巧》(第二版)第11章(26)
27.《Windows游戏编程大师技巧》(第二版)第11章(27)
28.《Windows游戏编程大师技巧》(第二版)第11章(28)
29.《Windows游戏编程大师技巧》(第二版)第11章(29)
30.《Windows游戏编程大师技巧》(第二版)第11章(30)
31.《Windows游戏编程大师技巧》(第二版)第11章(31)
32.《Windows游戏编程大师技巧》(第二版)第11章(32)
33.《Windows游戏编程大师技巧》(第二版)第11章(33)
34.《Windows游戏编程大师技巧》(第二版)第11章(34)
35.《Windows游戏编程大师技巧》(第二版)第11章(35)
36.《Windows游戏编程大师技巧》(第二版)第11章(36)
37.《Windows游戏编程大师技巧》(第二版)第11章(37)
38.《Windows游戏编程大师技巧》(第二版)第11章(38)
共38页 9 7 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [388 :>

《Windows游戏编程大师技巧》(第二版)第11章 相关文章:
《Windows游戏编程大师技巧》(第二版)第11章 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com