Sack Library Documentation
|
struct critical_section_tag { _32 dwUpdating; _32 dwLocks; THREAD_ID dwThreadID; THREAD_ID dwThreadWaiting; }; typedef struct critical_section_tag CRITICALSECTION; #define InitializeCriticalSection InitializeCriticalSec
Members |
Description |
_32 dwUpdating; |
this is set when entering or leaving (updating)... |
_32 dwLocks; |
count of locks entered. (only low 24 bits may count for 16M entries, upper bits indicate internal statuses. |
THREAD_ID dwThreadID; |
windows upper 16 is process ID, lower is thread ID |
THREAD_ID dwThreadWaiting; |
ID of thread waiting for this.. |
A custom implementation of windows CRITICAL_SECTION api. Provides same capability for Linux type systems. Can be checked as a study in how to implement safe locks.
The __Ex versions of functions passes source file and line information in debug mode. This can be used if critical section debugging is turned on, or if critical section logging is turned on. (See ... ) This allows applications to find deadlocks by tracking who is entering critical sections and probably failing to leave them.
For purposes of this example this is declared in global memory, known to initialize to all 0.
CRITICALSECTION cs_lock_test;
In some bit of code that can be executed by several threads...
{ EnterCriticalSec( &cs_lock_test ); // the code in here will only be run by a single thread LeaveCriticalSec( &cs_lock_test ); }
Copyright (c) 2000+. All rights reserved.
|
What do you think about this topic? Send feedback!
|