开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜