Anyone knows for what these apis are EnterCriticalSection, LeaveCriticalSection...?
It is used with threads.
They are kernel object:mutex,semphore,thread,process,critical section,all kernel object.
Get all info from MSDN,please:-)
Get all info from MSDN,please:-)
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.
-George
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.
-George
thanks huh, that was enough to a simple understanding.
cyaz :)
cyaz :)
Actually, critical sections are user mode objects, not kernel objects, so they can't be used inter-process.
Bye.
Bye.
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.
Smallwaves.
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.
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!!
Bye.
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!!
Bye.
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. :)