Do I need to use HeapLock and HeapUnlock functions in winapi whenever I want to use HeapAlloc or HeapFree?
Do I need to use HeapLock and HeapUnlock functions in winapi whenever I want to use HeapAlloc or HeapFree in a multithreaded program which use the same handle to a heap?
If yes, does HeapLock block开发者_开发技巧 until it gets the lock?
No. HeapLock
acquires the lock which is used by HeapAlloc
which you can use to lock out other threads from performing allocation and deallocation function on the specified heap but you must not use HeapLock
before calling HeapAlloc
or HeapFree
.
So long as the heap was not created with HEAP_NO_SERIALIZATION
, HeapAlloc
and HeapFree
are safe to use in a multithread environment.
References:
HeapAlloc
HeapLock
精彩评论