When implementing condition variables into a Win32 C++ program, would it be better to use Win32 functions, classes, and data types (e.g. CreateThread
, SleepConditionVariableCS
, WaitForSingleObjectEx
, ReleaseMutex
, CONDITION_VARIABLE
) or those from the C++11 standard libraries (e.g. thread
, wait
, join
, unlock
, condition_variable
)?
Since the answer to this question is probably not binary, what considerations should one take into account when making such a decision?
The C++ synchronization mechanisms are designed to C++ principles. They free their resources in the destructor, and they also use RAII to ensure safe locking. They use exceptions to signal errors.
Essentially, they are much harder to use incorrectly than the function-based native Windows API. This means that if you can use them (your implementation supports them), you always should use them.
Oh, and they are cross-platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With