为什么Mutex,Event,Thread句柄都是可以waitforsingleobject?

原创 2005年05月31日 02:07:00

原因比较简单,他们都是有个DISPATCHER_HEADER Header;的头部,EVENT只有这个头部(定义可以在DDK里面看到)

typedef struct _KTHREAD {

    //
    // The dispatcher header and mutant listhead are fairly infrequently
    // referenced, but pad the thread to a 32-byte boundary (assumption
    // that pool allocation is in units of 32-bytes).
    //

    DISPATCHER_HEADER Header;
    LIST_ENTRY MutantListHead;

    //
    // The following fields are referenced during trap, interrupts, or
    // context switches.
    //
    // N.B. The Teb address and TlsArray are loaded as a quadword quantity
    //      on MIPS and therefore must be on a quadword boundary.
    //

    PVOID InitialStack;
    PVOID StackLimit;
#if defined(_IA64_)
    PVOID InitialBStore;
    PVOID BStoreLimit;
#endif
    PVOID Teb;
    PVOID TlsArray;
    PVOID KernelStack;
#if defined(_IA64_)
    PVOID KernelBStore;
#endif
    BOOLEAN DebugActive;
    UCHAR State;
    BOOLEAN Alerted[MaximumMode];
    UCHAR Iopl;
    UCHAR NpxState;
    CHAR Saturation;
    SCHAR Priority;
    KAPC_STATE ApcState;
    ULONG ContextSwitches;

    //
    // The following fields are referenced during wait operations.
    //

    LONG_PTR WaitStatus;
    KIRQL WaitIrql;
    KPROCESSOR_MODE WaitMode;
    BOOLEAN WaitNext;
    UCHAR WaitReason;
    PRKWAIT_BLOCK WaitBlockList;
    LIST_ENTRY WaitListEntry;
    ULONG WaitTime;
    SCHAR BasePriority;
    UCHAR DecrementCount;
    SCHAR PriorityDecrement;
    SCHAR Quantum;
    KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
    PVOID LegoData;
    ULONG KernelApcDisable;
    KAFFINITY UserAffinity;
    BOOLEAN SystemAffinityActive;
    UCHAR PowerState;
    UCHAR NpxIrql;
    UCHAR Pad[1];
    PVOID ServiceTable;
//    struct _ECHANNEL *Channel;
//    PVOID Section;
//    PCHANNEL_MESSAGE SystemView;
//    PCHANNEL_MESSAGE ThreadView;

    //
    // The following fields are referenced during queue operations.
    //

    PRKQUEUE Queue;
    KSPIN_LOCK ApcQueueLock;
    KTIMER Timer;
    LIST_ENTRY QueueListEntry;

    //
    // The following fields are referenced during read and find ready
    // thread.
    //

    KAFFINITY Affinity;
    BOOLEAN Preempted;
    BOOLEAN ProcessReadyQueue;
    BOOLEAN KernelStackResident;
    UCHAR NextProcessor;

    //
    // The following fields are referenced during system calls.
    //

    PVOID CallbackStack;
#if defined(_IA64_)
    PVOID CallbackBStore;
#endif
    PVOID Win32Thread;
    PKTRAP_FRAME TrapFrame;
    PKAPC_STATE ApcStatePointer[2];
    CCHAR PreviousMode;
    UCHAR EnableStackSwap;
    UCHAR LargeStack;
    UCHAR ResourceIndex;

    //
    // The following entries are referenced during clock interrupts.
    //

    ULONG KernelTime;
    ULONG UserTime;

    //
    // The following fields are referenced during APC queuing and process
    // attach/detach.
    //

    KAPC_STATE SavedApcState;
    BOOLEAN Alertable;
    UCHAR ApcStateIndex;
    BOOLEAN ApcQueueable;
    BOOLEAN AutoAlignment;

    //
    // The following fields are referenced when the thread is initialized
    // and very infrequently thereafter.
    //

    PVOID StackBase;
    KAPC SuspendApc;
    KSEMAPHORE SuspendSemaphore;
    LIST_ENTRY ThreadListEntry;

    //
    // N.B. The below four UCHARs share the same DWORD and are modified
    //      by other threads. Therefore, they must ALWAYS be modified
    //      under the dispatcher lock to prevent granularity problems
    //      on Alpha machines.
    //

    CCHAR FreezeCount;
    CCHAR SuspendCount;
    UCHAR IdealProcessor;
    UCHAR DisableBoost;

} KTHREAD, *PKTHREAD, *RESTRICTED_POINTER PRKTHREAD;

//
// Process object structure definition
//

typedef struct _KPROCESS {

    //
    // The dispatch header and profile listhead are fairly infrequently
    // referenced, but pad the process to a 32-byte boundary (assumption
    // that pool block allocation is in units of 32-bytes).
    //

    DISPATCHER_HEADER Header;
    LIST_ENTRY ProfileListHead;

    //
    // The following fields are referenced during context switches.
    //

    ULONG_PTR DirectoryTableBase[2];

#if defined(_X86_)

    KGDTENTRY LdtDescriptor;
    KIDTENTRY Int21Descriptor;
    USHORT IopmOffset;
    UCHAR Iopl;
    BOOLEAN VdmFlag;

#endif

#if defined(_IA64_)

    KGDTENTRY LdtDescriptor;
    ULONGLONG UnscrambledLdtDescriptor;
    KIDTENTRY Int21Descriptor;
    BOOLEAN VdmFlag;

    REGION_MAP_INFO ProcessRegion;
    REGION_MAP_INFO SessionRegion;
    PREGION_MAP_INFO SessionMapInfo;
    ULONG_PTR SessionParentBase;

#endif // _IA64_

#if defined(_ALPHA_)

    union {
        struct {
            KAFFINITY ActiveProcessors;
            KAFFINITY RunOnProcessors;
        };

        ULONGLONG Alignment;
    };

    ULONGLONG ProcessSequence;
    ULONG ProcessAsn;

#else

    KAFFINITY ActiveProcessors;

#endif

    //
    // The following fields are referenced during clock interrupts.
    //

    ULONG KernelTime;
    ULONG UserTime;

    //
    // The following fields are referenced infrequently.
    //

    LIST_ENTRY ReadyListHead;
    LIST_ENTRY SwapListEntry;
    LIST_ENTRY ThreadListHead;
    KSPIN_LOCK ProcessLock;
    KAFFINITY Affinity;
    USHORT StackCount;
    SCHAR BasePriority;
    SCHAR ThreadQuantum;
    BOOLEAN AutoAlignment;
    UCHAR State;
    UCHAR ThreadSeed;
    BOOLEAN DisableBoost;
    UCHAR PowerState;
    BOOLEAN DisableQuantum;
    UCHAR Spare[2];
} KPROCESS, *PKPROCESS, *RESTRICTED_POINTER PRKPROCESS;

WaitForSingleObject等待一个mutex句柄时的返回值

今天遇到了用WaitForSingleObject去等待一个Mutex句柄,对他的两个返回值(WAIT_OBJECT_0和WAIT_ABANDONED)含义有点含糊,于是写了测试代码模拟了下   ...

线程句柄作WaitForSingleObject的参数是什么意思?

[cpp] view plaincopy #include    #include       DWORD WINAPI Fun1Proc(LPVOID lpPar...
  • L_Andy
  • L_Andy
  • 2015年01月28日 11:22
  • 1043

多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)

转自 http://www.cnblogs.com/freshman0216/archive/2008/07/30/1252345.html  本篇继续介绍WaitHandler类及其子类Mutex,...

c# 线程同步: 详解lock,monitor,同步事件和等待句柄以及mutex

最近由于在准备Collection对象培训的PPT,因为涉及到SyncRoot的属性的讲解,所以对怎样在多线程应用程序中同步资源访问做了个总结:对于引用类型和非线程安全的资源的同步处理,有四种相关处理...

多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(下)

前两篇简单介绍了线程同步lock,Monitor,同步事件EventWaitHandler,互斥体Mutex的基本用法,在此基础上,我们对它们用法进行比较,并给出什么时候需要锁什么时候不需要的几点建议...
  • iamdll
  • iamdll
  • 2011年05月23日 13:48
  • 388

C#多线程:深入了解线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)

本篇继续介绍WaitHandler类及其子类 Mutex,ManualResetEvent,AutoResetEvent的用法。.NET中线程同步的方式多的让人看了眼花缭乱,究竟该怎么去理解呢?其实,...
  • ruijc
  • ruijc
  • 2013年03月14日 19:50
  • 504

多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(下)

转自:http://www.cnblogs.com/freshman0216/archive/2008/08/07/1256919.html  前两篇简单介绍了线程同步lock,Monito...

多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(下)

同系列阅读:多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(上),多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)       前两篇...
  • Baple
  • Baple
  • 2012年01月05日 09:25
  • 736

多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(上)

转自 http://www.cnblogs.com/freshman0216/archive/2008/07/27/1252253.html  本篇从Monitor,Mutex,ManualReset...

索引节点号、文件描述符、句柄在形式上都是一个非负整数,它们的机制为何

1、系统给每个索引节点分配了一个号码,(该号码)也就是该节点在索引节点数组(即inode table)中的索引号(即数组下标号),称为索引节点号。 2、文件描述符在形式上是一个非负整数。实际...
  • haiross
  • haiross
  • 2014年09月11日 09:17
  • 779
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:为什么Mutex,Event,Thread句柄都是可以waitforsingleobject?
举报原因:
原因补充:

(最多只允许输入30个字)