游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1467|回复: 2

MSDN的一句话

[复制链接]

62

主题

331

帖子

366

积分

中级会员

Rank: 3Rank: 3

积分
366
QQ
发表于 2005-4-20 21:58:00 | 显示全部楼层 |阅读模式
struct RTL_CRITICAL_SECTION
{
    PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;
    HANDLE LockSemaphore;
    ULONG_PTR SpinCount;
};
“在多处理器系统中,如果该临界区不可用,调用线程将在对与该临界区相关的信号执行等待操作之前,旋转 dwSpinCount 次。如果该临界区在旋转操作期间变为可用,该调用线程就避免了等待操作。”

不好意思
没看懂
啥意思?[em24]

..

0

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2005-4-21 01:55:00 | 显示全部楼层

Re:MSDN的一句话

If the thread absolutely needs to own the resource before continuing, use EnterCriticalSection. For the moment, set aside the SpinCount test used on multiprocessor machines. This routine, like TryEnterCriticalSection, adjusts the bookkeeping for the critical section if it is free or already owned by the thread. It's important to note that the all-important LockCount increment is done using the x86 "lock" prefix. This ensures that only one CPU at a time can modify the LockCount field. (In fact, the Win32 InterlockedIncrement API is just an ADD instruction with the same lock prefix.)....

MSDN:http://msdn.microsoft.com/msdnmag/issues/03/12/CriticalSections/default.aspx

1

主题

7

帖子

7

积分

新手上路

Rank: 1

积分
7
发表于 2005-4-21 13:45:00 | 显示全部楼层

Re:MSDN的一句话

那是说如果有两个线程同时访问同一个临界对象,先进入临界区的线程会锁定该临界对象,导致另一个线程在进入临界区时等待,这种等待是一种对锁定状态的轮询,轮询的次数为dwSpinCount,如果该临界区在轮询期间变为可用,该调用线程就避免了等待操作进入该临界区域,如果超出线程放弃CPU时间片,等待下一个时间片继续此种轮询,先进入临界区的线程一直锁定该临界对象,等待线程会一直等待下去(死锁)。
看一下《Windows核心编程》你会对内核对象有所了解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-25 10:28

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表