473,573 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSingleLock() Assertion failure

I have some C++ code that uses the CSingleLock( CCriticalSectio n *)
constructor. In visual C++ 6.0, this code compiles and runs fine in both
Debug and release modes. However, in Visual Studio .Net, when I run this
code I get an Assertion failure. The error appears to be exactly the same as
that seen with CSingleLock in VC++ version 4.0. I can get around this by
using the Lock method of the CCriticalSectio n object but the accepted way to
do this is to use the CSingleLock object. Why do I get the Assertion failure?
Nov 17 '05 #1
5 5548
Ron Louzon wrote:
I have some C++ code that uses the CSingleLock( CCriticalSectio n *)
constructor. In visual C++ 6.0, this code compiles and runs fine in both
Debug and release modes. However, in Visual Studio .Net, when I run this
code I get an Assertion failure. The error appears to be exactly the same as
that seen with CSingleLock in VC++ version 4.0. I can get around this by
using the Lock method of the CCriticalSectio n object but the accepted way to
do this is to use the CSingleLock object. Why do I get the Assertion failure?


What's the text of the assertion?

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #2
Doug,

Here is the assertion failure that I get:

=============== =

Debug Assertion Failed!

Program: C:\Mydata\NetAp ps\Cmp\Debug\Cm p.exe
File: f:\vs70builds\3 077\vc\MFCATL\s hip\atlmfc\incl ude\afxmt.inl
Line: 81

For information on how your program can cause an assertion failure, see the
Visual C++ documentation on asserts.

=============== ==========

"Doug Harrison [MVP]" wrote:
Ron Louzon wrote:
I have some C++ code that uses the CSingleLock( CCriticalSectio n *)
constructor. In visual C++ 6.0, this code compiles and runs fine in both
Debug and release modes. However, in Visual Studio .Net, when I run this
code I get an Assertion failure. The error appears to be exactly the same as
that seen with CSingleLock in VC++ version 4.0. I can get around this by
using the Lock method of the CCriticalSectio n object but the accepted way to
do this is to use the CSingleLock object. Why do I get the Assertion failure?


What's the text of the assertion?

--
Doug Harrison
Microsoft MVP - Visual C++

Nov 17 '05 #3
Doug,

After the assertion failure, the debugger jumps to this code and shows the
failure as being on the line

"ASSERT(!m_bAcq uired);"

BOOL CSingleLock::Lo ck(DWORD dwTimeOut /* = INFINITE */)
{
ASSERT(m_pObjec t != NULL || m_hObject != NULL);
--> ASSERT(!m_bAcqu ired);

m_bAcquired = m_pObject->Lock(dwTimeOut );
return m_bAcquired;
}
"Doug Harrison [MVP]" wrote:
Ron Louzon wrote:
I have some C++ code that uses the CSingleLock( CCriticalSectio n *)
constructor. In visual C++ 6.0, this code compiles and runs fine in both
Debug and release modes. However, in Visual Studio .Net, when I run this
code I get an Assertion failure. The error appears to be exactly the same as
that seen with CSingleLock in VC++ version 4.0. I can get around this by
using the Lock method of the CCriticalSectio n object but the accepted way to
do this is to use the CSingleLock object. Why do I get the Assertion failure?


What's the text of the assertion?

--
Doug Harrison
Microsoft MVP - Visual C++

Nov 17 '05 #4
Ron Louzon wrote:
Doug,

Here is the assertion failure that I get:

============== ==

Debug Assertion Failed!

Program: C:\Mydata\NetAp ps\Cmp\Debug\Cm p.exe
File: f:\vs70builds\3 077\vc\MFCATL\s hip\atlmfc\incl ude\afxmt.inl
Line: 81

For information on how your program can cause an assertion failure, see the
Visual C++ documentation on asserts.


It didn't give you the text of the assertion? Oh well, here's what I find in
VC7.1:

_AFXMT_INLINE BOOL CCriticalSectio n::Lock(DWORD dwTimeout)
{ ASSERT(dwTimeou t == INFINITE); (void)dwTimeout ; return Lock(); }

From this, it appears you must be trying to use a non-INFINITE timeout,
which doesn't work with CRITICAL_SECTIO N objects. There are a number of
similar gotchas in the MFC synchronization classes, which are the result of
trying to make CRITICAL_SECTIO N look to C++ like a kernel object such as the
mutex. Another example would be passing a CCriticalSectio n to CMultiLock,
which ASSERTs because you cannot WaitForMultiple Objects on CRITICAL_SECTIO N.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #5
Doug,

That is exactly what I am trying to do. I have a timeout specified for the
CSingleLock call. Since that is a problem, I will pull it out and use and
infinite timeout. Thanks.

"Doug Harrison [MVP]" wrote:
Ron Louzon wrote:
Doug,

Here is the assertion failure that I get:

============== ==

Debug Assertion Failed!

Program: C:\Mydata\NetAp ps\Cmp\Debug\Cm p.exe
File: f:\vs70builds\3 077\vc\MFCATL\s hip\atlmfc\incl ude\afxmt.inl
Line: 81

For information on how your program can cause an assertion failure, see the
Visual C++ documentation on asserts.


It didn't give you the text of the assertion? Oh well, here's what I find in
VC7.1:

_AFXMT_INLINE BOOL CCriticalSectio n::Lock(DWORD dwTimeout)
{ ASSERT(dwTimeou t == INFINITE); (void)dwTimeout ; return Lock(); }

From this, it appears you must be trying to use a non-INFINITE timeout,
which doesn't work with CRITICAL_SECTIO N objects. There are a number of
similar gotchas in the MFC synchronization classes, which are the result of
trying to make CRITICAL_SECTIO N look to C++ like a kernel object such as the
mutex. Another example would be passing a CCriticalSectio n to CMultiLock,
which ASSERTs because you cannot WaitForMultiple Objects on CRITICAL_SECTIO N.

--
Doug Harrison
Microsoft MVP - Visual C++

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3158
by: Todd Miller | last post by:
Hi, I recently discovered an assertion failure in the Python garbage collection system when scripts using our C extension (numarray) exit. The assertion is activated for Pythons configured using --with-pydebug. I have a feeling I may be doing something wrong with garbage collection support for some of our c types, but I'm not sure exactly...
4
11089
by: Etayki | last post by:
Hi, I am getting an assertion failure when declaring a CInternetSession object: CInternetSession mySession; // a session object I am still able to run the program, but I receive that annoying assertion failure dialog box and I have to click "ignore" each time.
2
5410
by: Craig Klementowski | last post by:
Pardon the cross post, but I'm not sure where exactly to post this question. We have MFC application using many MFC extention DLL's. We started using a new MFC extention DLL that is mixed mode so we could use some .Net components we have built. We are getting an assertion in ~CCmdTarget when exiting our app when after making a call to...
9
2319
by: Bern McCarty | last post by:
I am porting stuff from MEC++ syntax to the new C++/CLI syntax. Something that we did in the old syntax that proved to be very valuable was to make sure that the finalizer would purposefully generate an assertion failure for unoptimized, debug builds. We did this to find and fix cases where we were relying upon finalization rather than...
2
5557
by: Pushpa | last post by:
Hi All, This my part of the c++ program using threads in windows : //modified by pushpa struct structExrdDoc { CExrdDoc* spDoc; LPCTSTR sstrFileName;
0
1378
by: scorpion06 | last post by:
Hello, i would like to know how can i rewrite the function "CSingleLock" without MFC, using only C++ and API Win32. thanks
1
1286
by: =?Utf-8?B?SWxpYW4=?= | last post by:
Hello there, I recently installed MS Office 2007. I have two computers- one runs XP and the second Media Center. When I type a letter in Ward the spell check doesn't work. When I close the document I receive a messege Assertion failure- Enable JIT. I tried to find how to enable JIT but I can't. Funnily this happens only in the Media Centre....
2
3397
by: rsr | last post by:
hi, I am unable to execute my application though I am able to build and compile it without warnings or errors, because of this. Debug Assertion failure file tcscat_s.inl line: 42 can anyone tell me what does this mean?
1
1861
by: aalam | last post by:
class base { int a; base(int x) { a=x; } ~base(); } class derive:public base
0
7781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7788
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.