⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readwrit.h

📁 侯捷先生翻译的书籍《Win32多线程程序设计》的源代码。
💻 H
字号:
/*
 * ReadWrit.h
 *
 * Sample code for Multithreading Applications in Win32
 * This is from Chapter 7, Listing 7-1
 *
 * Demonstrates an implementation of the
 * Readers/Writers algorithm. This version
 * gives preference to readers.
 */

///////////////////////////////////////////////////////

//
// Structure definition
//

typedef struct _RWLock
{
    // Handle to a mutex that allows
    // a single reader at a time access
    // to the reader counter.
    HANDLE	hMutex;

    // Handle to a semaphore that keeps
    // the data locked for either the
    // readers or the writers.
    HANDLE	hDataLock;

    // The count of the number of readers.
    // Can legally be zero or one while
    // a writer has the data locked.
	int		nReaderCount;
} RWLock;

//
// Reader/Writer prototypes
//

BOOL InitRWLock(RWLock *pLock);
BOOL DestroyRWLock(RWLock *pLock);
BOOL AcquireReadLock(RWLock *pLock);
int ReleaseReadLock(RWLock *pLock);
BOOL AcquireWriteLock(RWLock *pLock);
int ReleaseWriteLock(RWLock *pLock);
BOOL ReadOK(RWLock *pLock);
BOOL WriteOK(RWLock *pLock);

BOOL FatalError(char *s);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -