Original Post
I'm getting a strange error when I try to use CMutex and CSingleLock from the Visual Studio VC++. In my class I have something like this. class MyClass{ CMutex mMutex; CSingleLock *mSingleLockPtr; }; In my constructor, mSingleLockPtr = new CSingleLock(&mMutex); In my class I have a function CViewPort* GetViewPort() { mSingleLockPtr->Lock(); if(mViewPort == NULL) mViewPort = new CViewPort(); mSingleLockPtr->Unlock(); return mViewPort; } It returns the viewport and creates it if one hasn't been made. I have multiple threads running. I used the locking because I noticed sometimes multiple view ports were created and assigned to the same member. I wanted to make sure only one viewport was created. However, I get a strange error. An assertion failed in the SingleLock class. I know it's something wrong w/ the way I'm locking. When I remove it, the program runs fine even if new CViewPort gets called twice. I can't see anything obvious. It looks like one thread tries to get access once. While another one is trying multiple times. The one which tries multiple times seems to get control 1st. The 2nd thread does not seem to ever get access. However, I can't be sure because the app crashes out and go into the stack dump. Thanks in advance.