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

Discussion in 'C++' started by Zerex71, Mar 25, 2008.

  1. Zerex71

    Zerex71 Guest

    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

    // Inside my class' .cpp

    void MyClass::flush()
    // Method serves to do one thing and one thing only - clear both
    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.

    Zerex71, Mar 25, 2008
    1. Advertisements

  2. Zerex71

    Christopher Guest

    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.
    Christopher, Mar 25, 2008
    1. Advertisements

  3. Zerex71

    Christopher Guest

    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.
    Christopher, Mar 25, 2008
  4. Zerex71

    Zerex71 Guest

    It's hardly off-topic to ask a C++-related question on a C++ newsgroup.
    Zerex71, Mar 25, 2008
  5. Zerex71

    Zerex71 Guest

    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.

    Zerex71, Mar 25, 2008
  6. Zerex71

    Christopher Guest

    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

    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.
    Christopher, Mar 25, 2008
  7. Zerex71

    acehreli Guest

    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.

    acehreli, Mar 25, 2008
  8. Zerex71

    Christopher Guest

    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
    Christopher, Mar 25, 2008
  9. Zerex71

    Martin York Guest

    lock myObjectLocker(this); // *** offending LOC
    Martin York, Mar 25, 2008
  10. Zerex71

    Zerex71 Guest

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

    Zerex71, Mar 26, 2008
  11. Right, which is why it's off-topic here. Ask in a MS newsgroup.
    dave_mikesell, Mar 26, 2008
  12. http://tinylink.com/?3Eu8AMkJpR

    "First of all, please keep in mind that comp.lang.c++ is a group for
    of general issues of the C++ programming language, as defined by the
    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.
    dave_mikesell, Mar 26, 2008
  13. Zerex71

    Zerex71 Guest

    Still sounds C++-related to me. Next?
    Zerex71, Mar 26, 2008
  14. Zerex71

    Zerex71 Guest

    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.
    Zerex71, Mar 26, 2008
  15. The CLR's lock mechanism is in the C++ ISO standard?
    dave_mikesell, Mar 26, 2008
  16. 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++.
    Eric.Malenfant, Mar 26, 2008
  17. 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?
    dave_mikesell, Mar 26, 2008
  18. Zerex71

    peter koch Guest

    This is not a standard namespace.
    And lock is not a standard function...


    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 koch, Mar 26, 2008
  19. In message
    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

    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.
    Richard Herring, Mar 26, 2008
  20. Zerex71

    Zerex71 Guest

    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

    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.

    Zerex71, Mar 26, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.