Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

Lock in MC++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SMK - 05 Jun 2004 09:16 GMT
What is the equivalent of Lock keyword in MC++
Jesse McGrew - 05 Jun 2004 11:01 GMT
> What is the equivalent of Lock keyword in MC++

Monitor::Enter() and Leave() with a __finally block.

Jesse
smk - 05 Jun 2004 12:36 GMT
Thanks. It work
   
    ----- Jesse McGrew wrote: ----
   
    SMK wrote
    > What is the equivalent of Lock keyword in MC+
   
    Monitor::Enter() and Leave() with a __finally block
   
    Jess
Tomas Restrepo \(MVP\) - 05 Jun 2004 16:01 GMT
> > What is the equivalent of Lock keyword in MC++
>
> Monitor::Enter() and Leave() with a __finally block.

A nice way of wrapping it might be something similar to this:

#using <mscorlib.dll>
#include <vcclr.h>
using namespace System;

template <typename T>
struct sync_lock
{
private: gcroot<T> v_t;
public:
  sync_lock(T t) {
     v_t = t;
     System::Threading::Monitor::Enter(v_t);
  }
  ~sync_lock() {
     System::Threading::Monitor::Exit(v_t);;
  }
};

__gc class MyClass
{
private: int m_v;
public:
void DoIt()
{
          sync_lock<MyClass*> lock(this);
    m_v += 5;
}
};

int main()
{
MyClass* c = new MyClass();
c->DoIt();
}

Signature

Tomas Restrepo
tomasr@mvps.org


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.