为什么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;

CreateMutex WaitForSingleObject ReleaseMutex使用

HANDLE CreateMutex(  LPSECURITY_ATTRIBUTES lpMutexAttributes,//  BOOL bInitialOwner,  // flag for ...
  • luliyuan
  • luliyuan
  • 2014年10月28日 17:18
  • 7050

CreateMutex和WaitForSingleObject的用法

WaitForSingleObject的用法 DWORD WaitForSingleObject(   HANDLE hHandle,   DWORD dwMilliseconds ); 参数hHan...
  • ycanye2009
  • ycanye2009
  • 2016年03月21日 16:59
  • 382

WaitForSingleObject 等待线程句柄

http://blog.csdn.net/dyzhen/article/details/5993396 WaitForSingleObject(hThread/*某个线程的句柄*...
  • qq229596421
  • qq229596421
  • 2017年02月12日 17:04
  • 469

WaitForSingleObject 等待线程句柄

WaitForSingleObject(hThread/*某个线程的句柄*/,INFINITE)可以吗? hThread代表的线程如果在运行,就要一直等下去,直到线程退出来吗? 如果是这样...
  • dyzhen
  • dyzhen
  • 2010年11月07日 16:32
  • 2473

用WaitForSingleObject()函数实现简单的多线程互斥访问

今天是上班第一天,写了一个简单的线程互斥访问练习了一下多线程。虽然以前写过,但现在写还是碰到蛮多问题,比如WaitForSingleObject()函数加在哪个位置(可以用WaitForSingleO...
  • han43002
  • han43002
  • 2015年07月09日 14:27
  • 734

WaitForSingleObject()函数

VC声明DWORD WaitForSingleObject(   HANDLE hHandle,   DWORD dwMilliseconds   ); 参数hHandle是一个事...
  • s18754992795
  • s18754992795
  • 2016年07月15日 13:17
  • 4545

Qt多线程编程总结(二)——QMutex

QMutex类提供的是线程之间的访问顺序化。 QMutex的目的是保护一个对象、数据结构或者代码段,所以同一时间只有一个线程可以访问它。(在Java术语中,它和同步关键字“synchronize...
  • mznewfacer
  • mznewfacer
  • 2011年11月13日 21:39
  • 28973

CreateThread 与 WaitForSingleObject 的应用

做FW的升级小工具时,由于要与读写4M的文件
  • sanfenlu
  • sanfenlu
  • 2014年04月11日 15:29
  • 1579

WaitForSingleObject的详细用法

 用户模式的线程同步机制效率高,如果需要考虑线程同步问题,应该首先考虑用户模式的线程同步方法。   但是,用户模式的线程同步有限制,对于多个进程之间的线程同步,用户模式的线程同步方法无能为力。...
  • fuyuehua22
  • fuyuehua22
  • 2015年04月15日 13:52
  • 10198

再谈线程等待函数WaitForSingleObject和CloseHandle

多线程中使用WaitForSingleObject结束线程,啥也不说,先上代码 #include #include #include int Fun1Proc( void ) { int i...
  • kelery
  • kelery
  • 2016年06月30日 16:34
  • 2034
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:为什么Mutex,Event,Thread句柄都是可以waitforsingleobject?
举报原因:
原因补充:

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