Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Testing reader/writer locks

, 20 Jan 2009 CPOL
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 RWLockFavorNeither
{ 
public:
    RWLockFavorNeither();

	~RWLockFavorNeither();

	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)

Share

About the Author

Valery Grebnev
Software Developer
Canada Canada
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 21 Jan 2009
Article Copyright 2009 by Valery Grebnev
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid