Click here to Skip to main content
11,639,861 members (64,234 online)
Click here to Skip to main content
Add your own
alternative version

Testing reader/writer locks

, 20 Jan 2009 CPOL 35.5K 446 25
This article describes testing the results of reader/writer locks on Windows XP/Vista Uniprocessor and Multi-core PCs.
#pragma once 

template <typename lock_t>
class ref_shared_lock_t
{
public:
	ref_shared_lock_t(lock_t& lock) : m_lock(lock)
	{
		m_lock.acquireLockShared();
	}
	~ref_shared_lock_t()
	{
		m_lock.releaseLockShared();
	}
private:
	lock_t& m_lock;
	ref_shared_lock_t& operator=(const ref_shared_lock_t&); //C4512 warning
};

template <typename lock_t>
class ref_exclusive_lock_t
{
public:
	ref_exclusive_lock_t(lock_t& lock) : m_lock(lock)
	{
		m_lock.acquireLockExclusive();
	}
	~ref_exclusive_lock_t()
	{
		m_lock.releaseLockExclusive();
	}
private:
	lock_t& m_lock;
	ref_exclusive_lock_t& operator=(const ref_exclusive_lock_t&); //C4512 warning
};

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

You may also be interested in...

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