J Jesse McGrew Jun 5, 2004 #2 SMK said: What is the equivalent of Lock keyword in MC++ Click to expand... Monitor::Enter() and Leave() with a __finally block. Jesse
SMK said: What is the equivalent of Lock keyword in MC++ Click to expand... Monitor::Enter() and Leave() with a __finally block. Jesse
G Guest Jun 5, 2004 #3 Thanks. It work ----- Jesse McGrew wrote: ---- SMK wrote What is the equivalent of Lock keyword in MC+ Click to expand... Monitor::Enter() and Leave() with a __finally block Jess
Thanks. It work ----- Jesse McGrew wrote: ---- SMK wrote What is the equivalent of Lock keyword in MC+ Click to expand... Monitor::Enter() and Leave() with a __finally block Jess
T Tomas Restrepo \(MVP\) Jun 5, 2004 #4 Jesse McGrew said: Monitor::Enter() and Leave() with a __finally block. Click to expand... 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(); }
Jesse McGrew said: Monitor::Enter() and Leave() with a __finally block. Click to expand... 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(); }