473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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\msclr/lock.h(51) :
warning C4091: '' : ignored on left of 'int' when no variable is declared
..\testCPPConsoleApplication.cpp(12) : see reference to function template
instantiation 'msclr::lock::lock<System::Object>(T ^)' being compiled
with
[
T=System::Object
]

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 ReaderWriterLock.
is_not<T,
System::Threading::ReaderWriterLock>::__dont_use_t his_type__;
acquire(System::Threading::Timeout::Infinite);
}

... remainder of class definition...
};
Nov 11 '06 #1
1 6367
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 'ReaderWriterLock' 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 'ReaderWriterLock' 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::Threading::ReaderWriterLock>::__dont_use_t his_type__;
which reduces to:
is_not<T, System::Threading::ReaderWriterLock>::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
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
by: Shawn B. | last post by:
Greetings, What is the difference between lock(...) and Monitor.Enter(...) / Monitor.Exit(...) ? Thanks, Shawn
2
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
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...
6
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...
3
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...
6
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...
3
by: Tao | last post by:
hi.. Group, is there any lock statement like C# in managed C++? thanks
5
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.