I’m not sure if I correctly understand. TryEnterCriticalSection is called only once, it’s not stick like EnterCriticalSection?
E.g. if I write something like
if(TryEnterCriticalSection (&cs))
{
//do something that must be synh
LeaveCriticalSection(&cs);
}
else
{
//do other job
}
//go on
and if TryEnterCriticalSection returns false the part do something that must be synh will never be done, and do other job part will be exucuted and then go on?
You guessed right.
TryEnterCriticalSection()is called once, and tries to enter the critical section only once. If the critical section is locked, it returns false after the check.In general, if a function returns a boolean or an int, the if/else clauses behaves like following: