I just want to lock() - is that so wrong?

Z

Zerex71

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
 
C

Christopher

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

Looks to me that you require the documentation for msclr/lock.h and
the type you are using that comes from there. I'll make an educated
guess and say that's some port of types from C# to Linux using C++.
However, that type is no part of the C++ language itself, but rather
part of some third party library. The thing to do then is read the
documentation for the library you are using, ask on NGs or forums
dedicated to that library. It is off-topic here.
 
C

Christopher

Looks to me that you require the documentation for msclr/lock.h and
the type you are using that comes from there. I'll make an educated
guess and say that's some port of types from C# to Linux using C++.
However, that type is no part of the C++ language itself, but rather
part of some third party library. The thing to do then is read the
documentation for the library you are using, ask on NGs or forums
dedicated to that library. It is off-topic here.

P.S
If you don't like that answer. Multithreading libraries are (right
now) specific to your OS, except maybe boost if it has anything. You
could always use the multithreading mechanism native to your platform.
In which case, I'd Google pthreads for Linux.
 
Z

Zerex71

Looks to me that you require the documentation for msclr/lock.h and
the type you are using that comes from there. I'll make an educated
guess and say that's some port of types from C# to Linux using C++.
However, that type is no part of the C++ language itself, but rather
part of some third party library. The thing to do then is read the
documentation for the library you are using, ask on NGs or forums
dedicated to that library. It is off-topic here.

It's hardly off-topic to ask a C++-related question on a C++ newsgroup.
 
Z

Zerex71

P.S
If you don't like that answer. Multithreading libraries are (right
now) specific to your OS, except maybe boost if it has anything. You
could always use the multithreading mechanism native to your platform.
In which case, I'd Google pthreads for Linux.

I should clarify and say that I have not ported the C# to the box yet,
because I am doing the C++ conversion on my MS box at the moment.
Once that compiles, I'll deal with the lib differences between MSXP
and RHEL.

Mike
 
C

Christopher

It's hardly off-topic to ask a C++-related question on a C++ newsgroup.

According to who? You?
Read the FAQ: Google "parashift C++ faq lite"

This NG is not for everything "C++ related" it is for the C++ language
itself.

I cannot come here and expect people to start a discussion about
"RainbowBriteAndFriends.lib" that I happened to find on a website
somewhere. You can, however ask about _standard_ C++ libraries and
their use.
 
A

acehreli

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
[...]
It is off-topic here.

You are focusing on extra information given, which may be off-topic;
but the OP is asking why the compiler thinks a copy constructor is
needed there.

Ali
 
C

Christopher

You are focusing on extra information given, which may be off-topic;
but the OP is asking why the compiler thinks a copy constructor is
needed there.

Ali

And who knows without seeing the definition of lock which is defined
in the third party library.

There is no telling what lock is. Is it even a class? It could be a
function... who knows. Hell, maybe its a macro. I think its obvious he
is calling something that doesn't exist, but no one can tell him what
does exist, except those that are familiar with his third party
library.
 
M

Martin York

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
 
Z

Zerex71

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
 
D

dave_mikesell

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

Right, which is why it's off-topic here. Ask in a MS newsgroup.
 
D

dave_mikesell

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++".

http://tinylink.com/?3Eu8AMkJpR

"First of all, please keep in mind that comp.lang.c++ is a group for
discussion
of general issues of the C++ programming language, as defined by the
ANSI/ISO
language standard. If you have a problem that is specific to a
particular system
or compiler, you are much more likely to get complete and accurate
answers in a
group that specializes in your platform. A listing of some newsgroups
is given
at the end of this post.
"
 
Z

Zerex71

http://tinylink.com/?3Eu8AMkJpR

"First of all, please keep in mind that comp.lang.c++ is a group for
discussion
of general issues of the C++ programming language, as defined by the
ANSI/ISO
language standard. If you have a problem that is specific to a
particular system
or compiler, you are much more likely to get complete and accurate
answers in a
group that specializes in your platform. A listing of some newsgroups
is given
at the end of this post.
"

Still sounds C++-related to me. Next?
 
Z

Zerex71

Right, which is why it's off-topic here. Ask in a MS newsgroup.

I didn't know we were so tribal about what we could talk about here.
You'd think the C++ experts would jump at the chance to help with
questions of this nature.
 
E

Eric.Malenfant

I didn't know we were so tribal about what we could talk about here.

There is no tribality here (well not in this thread, at least ;-).
It's just that, IIUC, your question is about porting from C# to C++/
CLI, which is a different language than C++.
 
D

dave_mikesell

I didn't know we were so tribal about what we could talk about here.
You'd think the C++ experts would jump at the chance to help with
questions of this nature.

Chances are if anyone here knew the CLR, they might offer help, along
with a gentle nudge to the right newsgroup.

It's not that we're tribal, it's that we don't want the newsgroup
flooded with platform-specific questions when newsgroups dedicated to
those platforms exist. Pointing you in their direction is meant to
be help, not serve as a personal attack.

I could ask OpenGL questions here, but why would I when
comp.graphics.api.opengl exists?
 
P

peter koch

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

This is not a standard namespace.
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

And lock is not a standard function...

[snip]

My guess is that you are compiling for C++/CLR. That name is quite
unfortunate, because it is not C++. I do not know if I qualify as a C+
+ expert, but I do believe that I know the language very well, but we
are in no position to help you here. Microsoft has lots of groups and
lots of knowledgeable experts participate in that group (many of them
I believe, are from Microsoft). So ask your question there - it serves
you much better (and far better than your questioning the topicality
of your posts).

/Peter
 
R

Richard Herring

In message
Still sounds C++-related to me.

From the hint "// Also set /clr compile option in the project
properties" it sounds C++/CLI related to me. Despite the misleadingly
similar name, that's an entirely different language.

Keep digging, and all the knowledgeable posters here will surely push
you into the resulting pit, or their killfiles.

Did you read this part of the FAQ?

"Include the smallest, complete and compilable program that exhibits
your
problem."

That would as a minimum have included the definition of your "lock"
class or function, or whatever it is, since it is not a part of the C++
standard and nobody here can read minds.
 
Z

Zerex71

There is no tribality here (well not in this thread, at least ;-).
It's just that, IIUC, your question is about porting from C# to C++/
CLI, which is a different language than C++.

I was asking because locking things, mutexing, etc. and so forth seems
a pretty standard C++ feature, even if by "standard" it is part of
some thing like the STL. My hope was that someone here had the answer
rather than jumping on me for the semantic equivalent of jaywalking.
I had hoped someone who had done this in C++ had the answer. More
effort has been expending on trying to get me to report than to
actually producing the answer (Lord knows how nerds hate when you put
something in the wrong box).

To me, there is nothing *that* off-topic about asking about this
question. Sure, there is the CLR keyword that jumps out, but lock is
part of C++, at least Microsoft's interpretation of it. Perhaps a
renaming of the newsgroup should be in order? I saw plenty of things
posted to this group that had the stamp of "programming question" on
it. If someone here doesn't like the content, then make the group
moderated.

If I had a truly Windows-specific question, then I would have went
looking there (i.e MFC, forms, .NET, UI, MSDN, etc.) but this seems
pretty generic. Oh well. On to bigger and better things.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top