Why does Windows have no DeleteConditionVariable() function to go together with InitializeConditionVariable()?
Asked Answered
C

1

10

I'm trying out Windows support for Condition Variables today (as provided by Microsoft for Windows Vista and later). To initialize a condition variable, I call InitializeConditionVariable(), which is straightforward enough, but I don't see any way provided to destroy the condition variable when I'm done using it. Why is there no DeleteConditionVariable() function?

(I'd expect the API to be analogous to the existing CreateCriticalSection() / DestroyCriticalSection() API)

Consecrate answered 10/3, 2015 at 23:27 Comment(3)
My understanding is that there's just nothing that needs to be released; initializing a condition variable doesn't allocate memory or any sort of kernel object, and the condition variable itself is not added to any sort of list. So you can simply deallocate it or let it fall out of scope, provided of course that no other thread is currently using it.Hyperesthesia
MSDN: "Condition variables are user-mode objects". That means it is up to you to create and destroy them. No CreateConditionVariable() function either. Use a variable.Turrell
@HansPassant: not really convincing, IMO, because the very similar expression "user objects" includes a number of object types that do need deletion. (Of course, the documentation for creating such objects always explicitly explains how to delete them, if it is necessary.)Hyperesthesia
T
9

A conditional variable is a very light-weight object that is internally based on a single global kernel keyed event object that is always available through every process's entire lifetime. The conditional variable simply contains a pointer to that object. So there is nothing that needs to be freed explicitly, thus no delete function is needed.

Thissa answered 11/3, 2015 at 8:11 Comment(1)
Seems like an abstraction leakCadmium

© 2022 - 2024 — McMap. All rights reserved.