Click here to Skip to main content
15,879,096 members
Articles / Desktop Programming / Win32

Testing reader/writer locks

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
20 Jan 2009CPOL7 min read 76K   742   25  
This article describes testing the results of reader/writer locks on Windows XP/Vista Uniprocessor and Multi-core PCs.
#pragma once

#include <windows.h>

class RWLockFavorWriters
{
public:
    RWLockFavorWriters();

	~RWLockFavorWriters();

	void acquireLockShared();

	void acquireLockExclusive();

	void releaseLockShared();

	void releaseLockExclusive();

	DWORD numberReaderRacesLost() const
	{
#if defined(TRACK_READER_RACES)

		return numReaderRacesLost_;

#else

		return 0;

#endif
	}

	DWORD numberReaderWakeups() const
	{
#if defined(TRACK_READER_RACES)

		return numReaderWakeups_;

#else
		return 0;

#endif
	}

private:
    LONG numWritersWaiting_;
    LONG numReadersWaiting_;

    // HIWORD is writer active flag;
    // LOWORD is readers active count;
    DWORD activeWriterReaders_;

    HANDLE hReadyToRead_;
    HANDLE hReadyToWrite_;
    CRITICAL_SECTION cs_;

	DWORD numReaderRacesLost_;

	DWORD numReaderWakeups_;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions