Click here to Skip to main content
15,891,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'll appreciate it very much if you could give me a tip with the problem below.

thisClass.cpp is now complied with "clr", so < mutex > is not any more allowed!
I have replaced mutex with new msclr/lock.h, but cannot give the lock a managed object, since this is an unmanaged object!

C++
#include "thisClass.h"
// #include < mutex >
#include < msclr/lock.h >

// std::mutex mutexLock;


void * thisClass::fo(){
      // mutexLock.lock();
      lock l(this);   <<<<< this is not Ok, since "this" is an unmanaged object!!!

      :::::
                                   
     // mutexLock.unlock();    

}
Posted
Updated 4-Mar-15 0:14am
v2

1 solution

Not a nice solution but I decided to give an empty managed object to the class. It seems to function, but to me a strange solution!

Is there a better way? Could I avoid repeated "gcnew somehow!"?

C++
#include < msclr/lock.h >

using namespace msclr;    // << added missing namespace

ref class lockRef{
    static lockRef^ _lockRef;
}

void * thisClass::fo(){
  lockRef^ x = gcnew lockRef();  // <<  outside definitions were flagged as error!!!
  lock l(x)
  :::::
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900