i have often random crashes while entering the critical section.
InitializeCriticalSection(&m_lock); is saved as a class variable.
it crashes randomly, especially when the function which locks/unlock get more often called.
on destroy class.
On every lock call it wont get locked a second time, and unlocks instantly when not used anymore.
Are there some things i have to look about, or some alternatives?
This programm have around 45 threads.
I'd guess it was a memory overwrite that's hitting the CS data structure. I've used critical sections with more threads than that in the server of an authentication service than ran for years.
Don't use a Mutex instead, just because you appear to have problems with CriticalSections.
You should be wrapping these Platform API objects in C++ or using a library (like Boost), but ensure that it's using CriticalSections and NOT Mutexes. The two are different things with different applications.