What does the Win32 CRITICAL_SECTION contain?

谁说胖子不能爱 提交于 2019-12-10 16:46:51

问题


What data does the Win32 CRITICAL_SECTION contain, and how big is it?

This is undocumented and presumably implementation specific, but I'm curious to know


回答1:


This is from my installation of Windows Vista SDK:

WinNT.h:

typedef struct _RTL_CRITICAL_SECTION {
    PRTL_CRITICAL_SECTION_DEBUG DebugInfo;

    //
    //  The following three fields control entering and exiting the critical
    //  section for the resource
    //

    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
    HANDLE LockSemaphore;
    ULONG_PTR SpinCount;        // force size on 64-bit systems when packed
} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;

WinBase.h:

typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;



回答2:


Why don't you check the headers files?
Check out WINNT.H and see what you'll find out :)

(assuming that you have Windows C++ files)

Usually the structure contains:

LONG LockCount;
LONG RecursionCount;
HANDLE OwningThread;
HANDLE LockSemaphore;
DWORD SpinCount;

Edit: a command like sizeof(CRITICAL_SECTION) will reveal the size.



来源:https://stackoverflow.com/questions/2342025/what-does-the-win32-critical-section-contain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!