kadina
kadina

Reputation: 5376

Does thread need to get the ownership of the mutex to close the handle of the mutex

I saw some example programs about using mutexes. I was just wondering whether a thread has to get the ownership of the mutex to close the handle because one of the examples created a mutex as below in main().

ghmu_handle = CreateMutex(NULL, false, NULL);

And then it

Is it correct way or do we need to get the ownership to close the handle?

Upvotes: 0

Views: 123

Answers (1)

Harry Johnston
Harry Johnston

Reputation: 36308

No, you do not need to own the mutex to close the handle. That would be an unreasonable requirement, since it may not be possible to claim ownership of the mutex, e.g., if another process holds it.

Also note that you cannot release the mutex without the handle.

Upvotes: 1

Related Questions