Re: Do I need to worry about a failure in these synchronization APIs?
Arjay, RAII is simply a technique of encapsulating sensitive resources in an object with the main goal of utilizing its destructor to auto-release them. The point of my question here is whether synchronization API could fail when it's encapsulated in a simple synchronization struct. Sorry, but RAII had no answer to it. And by the way, it's not a panacea either. In the hands of a person who doesn't understand what they are doing it may be as dangerous as not using it.
Re: Do I need to worry about a failure in these synchronization APIs?
I'm aware of what RAII does with regard to threading issues. I guess your question is a bit strange based on your examples. With a critical section and your code (with a cs replacing the mutex), you'll have problems if you don't call LeaveCriticalSection (which is easy to do with non-RAII code).
If you encapsulate the thread synchronization within class(es) and provide accessor methods and use RAII to implement the synchronization you'll be well on your way to creating bulletproof threading.
Most of the problems that I see devs run into are from writing code that manually locks and unlocks because it's hard to unlock in all code paths without making a mistake. RAII solves this problem.
Another mistake by programmers (in combination with above) is they don't encapsulate the thread synchronization and have locking/unlocking everywhere in their code. This approach makes it difficult to determine where a resource has been locked and whether it's been unlocked.
To me, about 99% of threading problems are eliminated by avoiding those two mistakes. I write a lot of multi-threaded code. By following my own advice of using RAII and encapsulation, I rarely ever have thread synchronization issues once I've passed the initial develop and debug stage.
I have never found the synchronization apis to be unreliable, but maybe that is because of the approach I take.