Anyone knows for what these apis are EnterCriticalSection, LeaveCriticalSection...?
Posted on 2002-01-25 17:46:18 by coder
It is used with threads.
Posted on 2002-01-25 17:49:59 by CodeLover
They are kernel object:mutex,semphore,thread,process,critical section,all kernel object.

Get all info from MSDN,please:-)
Posted on 2002-01-26 14:37:50 by smallwaves
If you have a multi-threaded application, and as each of the threads work each reads and updates an array of data.

If one of those threads is in the middle of updating the array of data and its timeslice finishes and another thread reads the data it is possibly going to get incorrect results.

But, if you create a critical section for the data, and each thread call EnterCriticalSection when it is about to use the data, then while the first thread uses the data, all other threads are placed in a wait state until the access is freed using LeaveCriticalSection. In which each waiting threads get access one by one.

Posted on 2002-01-26 15:44:29 by huh
thanks huh, that was enough to a simple understanding.

cyaz :)
Posted on 2002-01-26 20:55:46 by coder
Actually, critical sections are user mode objects, not kernel objects, so they can't be used inter-process.
Posted on 2002-01-26 21:33:33 by GogetaSSJ4
Hi,GogetaSSJ4 :
What I mean is that they all have security-propeties and all need use "CloseHandle" to reduce times they have plused.
Sorry for my wrong naming them.

Posted on 2002-01-29 02:18:05 by smallwaves
Sorry, but no =)
Critical sections don't have security properties (if what you meant was SECURITY_ATTRIBUTES), and also, you don't have to use CloseHandle on them (you use LeaveCriticalSection).
Hope that helps!!
Posted on 2002-01-29 12:36:14 by GogetaSSJ4
Actualy to be technicaly correct, LeaveCriticalSection releases a threads 'hold' on the critical section. DeleteCriticalSection is used for closing a Critical Section and removing any system resources, memory etc used. :)
Posted on 2002-01-29 23:53:30 by huh