Re: Locking Resources
- From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
- Date: Sun, 24 Apr 2005 18:55:34 -0500
Coder wrote:
hi, may be this is not the right place to ask this question.
In my MFC application i need to lock a resource, i dont now what kind of mechanism to use exactly in microsoft environment .
Let the resource be a STL vector. this is a shared vector in a multithreaded application.
i need somehting like; <code>
mutex.lock() // vector operations .. mutex.unlock()
</code>
each thread thats wants to access this vector must sleep if resource is locked.
Best Regards...
MFC provides CCriticalSection for this, but its design and documentation are obscure. I suggest the simpler Win32 CRITICAL_SECTION object. Initialize the object with InitializeCriticalSection, then do this in each thread that accesses the shared data...
EnterCriticalSection(&cs); // vector operations .. LeaveCriticalSection(&cs);
-- Scott McPhillips [VC++ MVP]
.
- Follow-Ups:
- Re: Locking Resources
- From: Code4u
- Re: Locking Resources
- References:
- Locking Resources
- From: Coder
- Locking Resources
- Prev by Date: Re: Locking Resources
- Next by Date: Re: slow toolbar updates
- Previous by thread: Re: Locking Resources
- Next by thread: Re: Locking Resources
- Index(es):
Relevant Pages
|