I have implemented a simple read/write lock without using a critical section. I have tested my code by running 50 threads reading and writing the same data..h file#pragma once#include stdafx.hclass CReadWriteLock{public:    CReadWriteLock(void);    virtual ~CReadWriteLock(void);    void LockReader();    void UnlockReader();    void LockWriter();    void UnlockWriter();private:    CReadWriteLock(const CReadWriteLock &cReadWriteLock);    const CReadWriteLock& operator=(const CReadWriteLock &cReadWriteLock);    void IncrementReaderCount();    void DecrementReaderCount();    HANDLE m_hWriteMutex;    HANDLE m_hNoReadersEvent;    int m_nReaderCount;};.cpp file#include StdAfx.h#include ReadWriteLock.hCReadWriteLock::CReadWriteLock(void) : m_nReaderCount(0), m_hWriteMutex(NULL), m_hNoReadersEvent(NULL){    m_hWriteMutex    = CreateMutex(NULL, FALSE, NULL);    m_hNoReadersEvent = CreateEvent(NULL, TRUE, TRUE, NULL);}CReadWriteLock::CReadWriteLock(const CReadWriteLock &cReadWriteLock){}const CReadWriteLock& CReadWriteLock::operator=(const CReadWriteLock &cReadWriteLock){    return *this;}CReadWriteLock::~CReadWriteLock(void){    LockWriter(); // This will wait for finishing of all read/write operation.    UnlockWriter();    CloseHandle(m_hWriteMutex);    CloseHandle(m_hNoReadersEvent);}void CReadWriteLock::LockReader(){    WaitForSingleObject(m_hWriteMutex, INFINITE); // This will acquire write mutex    IncrementReaderCount();    ReleaseMutex(m_hWriteMutex); // Release write mutex}void CReadWriteLock::UnlockReader(){    // Decrement number of readers.    WaitForSingleObject(m_hWriteMutex, INFINITE); // This will acquire write mutex    DecrementReaderCount();    ReleaseMutex(m_hWriteMutex); // Release write mutex}void CReadWriteLock::LockWriter(){    HANDLE handles[] = {m_hWriteMutex, m_hNoReadersEvent};     WaitForMultipleObjects(2, handles, TRUE, INFINITE);}void CReadWriteLock::UnlockWriter(){    // Release Write mutex.    ReleaseMutex(m_hWriteMutex);}void CReadWriteLock::IncrementReaderCount(){    m_nReaderCount++;    // Reset the no readers event.    ResetEvent(m_hNoReadersEvent);}void CReadWriteLock::DecrementReaderCount(){    m_nReaderCount--;    // Are all readers out?    if(m_nReaderCount <= 0)    {        // Set the no readers event.        SetEvent(m_hNoReadersEvent);    }}I want to know if I have overlooked something.// ReadWriteLockTest.cpp ://#include stdafx.h#include ReadWriteLock.hconst int THREADCOUNT = 50;const int LOOP = 1000;DWORD WINAPI TestFunction( LPDWORD );CReadWriteLock glock;int gData = 0;int* gpData = 0;int _tmain(int argc, _TCHAR* argv[]){    HANDLE aThread[THREADCOUNT];    DWORD ThreadID;    DWORD i;    // Create worker threads    gpData = new int(10); // Init    for( i=0; i < THREADCOUNT; i++ )    {        aThread[i] = CreateThread(                      NULL,       // default security attributes                     0,          // default stack size                     (LPTHREAD_START_ROUTINE) TestFunction,                      NULL,       // no thread function arguments                     0,          // default creation flags                     0);         if( aThread[i] == NULL )        {            printf(CreateThread error: %d\n, GetLastError());            delete gpData;            return 1;        }    }    // Wait for all threads to terminate    WaitForMultipleObjects(THREADCOUNT, aThread, TRUE, INFINITE);    // Close thread and mutex handles    for( i=0; i < THREADCOUNT; i++ )        CloseHandle(aThread[i]);    delete gpData;    return 0;}DWORD WINAPI TestFunction( LPDWORD lpParam ){     for(int h = 0 ; h < LOOP; ++h)    {        if(h % 2 != 0)        {            // Reader            glock.LockReader();            printf_s(H= %d Reader Data= %d, DataPtr= %d\n, h, gData, *gpData);            if(h%5 == 0)                Sleep(10);            glock.UnlockReader();        }        else        {            // Writer            glock.LockWriter();            printf_s(H= %d Writer\n, h);            if(h%3 == 0)                Sleep(10);            gData = h;            delete gpData;            gpData = new int(h*2);             glock.UnlockWriter();        }    }    return TRUE; }This code breaks if I use more than 70 threads. Is my test case correct?
Simple read/write lock without using a critical section
c++;locking;synchronization