Re: I just want to lock() - is that so wrong?
On Mar 25, 7:55 pm, Martin York <Martin.YorkAma...@gmail.com> wrote:
On Mar 25, 1:21 pm, Zerex71 <mfeher1...@gmail.com> wrote:
Greetings group,
I am stumped by the following situation: I completed a phase in coding
my design in C# and all was smooth as silk, until I began the
conversion to C++ for an embedded non-M$ platform (RHEL box). The
problem I am running into is the following: I just want to convert the
C# lock(this) statement into C++ but no matter what I do, the compiler
balks. I am using MS VS2005. Here's the long and short of it:
#include <msclr\lock.h>
using namespace msclr; // Also set /clr compile option in the project
properties
// Inside my class' .cpp
void MyClass::flush()
{
// Method serves to do one thing and one thing only - clear both
queues
lock(this); // *** offending LOC
while (!incomingQueue.empty()) incomingQueue.pop();
while (!outgoingQueue.empty())) outgoingQueue.pop();
}
I get a complaint by the compiler that msclr::lock does not have a
copy constructor (like I care, right?). I just want to do the
conversion and be on with life. It's been about 3 years since I've
done C++ and looking at some of the converted code (I used a free tool
online to get me going), it put a whole bunch of other looks-legit-but-
I-have-no-idea-or-even-care stuff in my files. I don't think this
should be a difficult task. Perhaps I'm forgetting something because
lock (defined in lock.h) is a template class, but I just want to shut
the compiler up and move on with life.
Thanks in advance for any help you can provide.
Mike
Try:
lock myObjectLocker(this); // *** offending LOC
You know, I tried that, and it didn't work for me. That is similar to
both of the LOCs I have seen in the MSDN and other online examples,
and it still didn't work. I've even tried "lock myLock = new
lock(this)" or lock l<MyClass> or things or that nature. None of it
works. This lock.h, which is part of the MS CLR (as evidenced by the
namespace) is not something some Joe Blow cooked up - it's part of the
native VS2005 package. I don't know where else to turn.
And, while we're on the topic of what's on topic, tell me again why a
poster wouldn't want to post a C++-related thread on a newsgroup that
is called "comp.lang.c++".
Mike