473,729 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sample code for msclr::lock in online help generates warning message

Ian
I've just discovered the msclr::lock class in the C++ Support Library online
documentation. This seems like a much cleaner way to implement thread
protection than using monitor::enter/try/finally/monitor exit. However, I
cannot get around one of the warning messages and am requesting help in
understanding what is causing the warning.

All of the online sample code for the class msclr::lock generates the same
warning message. I have provide simplified code below that generates the
same warning message. The problem appears to be related to the typedef
'is_not' in the msclr::lock constructor. Can anyone help me out and explain
why this warning is occurring and how to work around it. I have limited
working experience with templates and this is the first time I've come
across a case where the class constructors are declared as templates but the
class isself is not. Can anyone explain what the warning means and what I
must do to avoid this warning message? I am working with VS2005, WinXP Pro
(SP2) and have the compiler warning level is set to 3.

Thanks for any and all help

Ian
SAMPLE CODE THAT GENERATES THE WARNING MESSAGE
=============== =============== =============== ===
#include "stdafx.h"
#include <msclr/lock.h>

using namespace System;

int main()
{
Object ^pObject = gcnew Object();
msclr::lock oL( pObject );
}

COMPILER WARNING MESSAGE
=============== ===========
C:\Program Files\Microsoft Visual Studio 8\VC\include\ms clr/lock.h(51) :
warning C4091: '' : ignored on left of 'int' when no variable is declared
..\testCPPConso leApplication.c pp(12) : see reference to function template
instantiation 'msclr::lock::l ock<System::Obj ect>(T ^)' being compiled
with
[
T=System::Objec t
]

PARTS IN CLASS 'MSCLR::LOCK' THAT PRODUCE THE WARNING
=============== =============== =============== ==
namespace msclr
{
ref class lock
{
private:
System::Object ^ m_object;
bool m_locked;

template<class T,class Uvalue struct is_not { typedef int
__dont_use_this _type__; };

public:
template<class Tlock( T ^ _object)
: m_object( _object ),
m_locked( false )
{
// ensure that T is not a ReaderWriterLoc k.
is_not<T,
System::Threadi ng::ReaderWrite rLock>::__dont_ use_this_type__ ;
acquire(System: :Threading::Tim eout::Infinite) ;
}

... remainder of class definition...
};
Nov 11 '06 #1
1 6416
Ian
I think I've have found the answer to my questions and am posting it here in
the event that this might be of interest to anyone else that is also
starting to use C++/CLI.

There are 2 overloads to the template based value structure 'is_not'. I
found that the overload used by the compiler depends on the template
argument 'T'. If 'T' is a 'ReaderWriterLo ck' then a compiler error is
generated, otherwise only the warning message is generated. In other words,
the compile selects the appropriate 'is_not' overload based on whether the
template arguments are of the same type or not. So 'is_not' is simply used
to ensure the lock object is not a 'ReaderWriterLo ck' and the warning
generated when any other type is used as a lock object can simply be
ignored.

Warning message c4091 can also be generated with the following line:
int;

This same warning message is generated for:
is_not<T, System::Threadi ng::ReaderWrite rLock>::__dont_ use_this_type__ ;
which reduces to:
is_not<T, System::Threadi ng::ReaderWrite rLock>::int;

So the warning message can safely be ignored and I've disabled it by adding:
#pragma warning( disable : 4091 )
Ian
Nov 12 '06 #2

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

Similar topics

0
4171
by: Subrahmanyam Arya | last post by:
Dear oracle gurus, Does any body have a sample online hotbackup script for UNIX. My oracle version is oracle 8.1.7.4 running on solaris 8. -your help is appreciated, sincerely avsrk
2
13203
by: Shawn B. | last post by:
Greetings, What is the difference between lock(...) and Monitor.Enter(...) / Monitor.Exit(...) ? Thanks, Shawn
2
1998
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
4
2158
by: Mrinal Kamboj | last post by:
Hi , I had a doubt regarding a piece of code with me , that has to do with System.Threading.Thread class . In it user instantiates an array of Thread class and to all of them assign a method for execution using ThreadStart Delegate say "worker" method . Now in the worker method there's a piece of code :
6
5996
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the original value of the local." My code is: using System; using System.Collections.Generic;
3
1562
by: daniel | last post by:
Maybe I'm not understanding things. I have a multi-threaded callback producer (Unmanaged C++), which fires into a managed proxy class, which in turn calls into a managed C++ consumer (mixed mode DLL). From the managed C++ class I have defined __events, which are consumed by a C# class. This works perfectly well; All the callbacks end up in the managed c++ class and successfully call into the C# code, however the raise_XXX method for the...
6
4053
by: Peted | last post by:
Hi wondering what is the best way to do this Need a user to click a button, that sends 3 or 4 string based commands via a TCP/ip socket link I can connect to the ip device no problems, am using indy sockets, and can send information ok
3
19029
by: Tao | last post by:
hi.. Group, is there any lock statement like C# in managed C++? thanks
5
7193
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my local server it was working fine but giving some errors those are Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line 116 Notice: Undefined variable: username in C:\Inetpub\wwwroot\sampleft\index.php on line 116 ...
0
8921
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8151
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.