Don't know about critical section in c
Hi All,
While referring one C programming book I found one concept known as 'critical section'. I didn't get what does the exact meaning of 'critical section' in C programming. Have you aware about the 'critical section in c'? if yes then please share your knowledge with me so that I can clear my doubts regarding the 'critical section'
Re: Don't know about critical section in c
Hi,
Critical section in C programming is the some part of code which can be assessable by multiple processes and threads at the single time. This part of program code is get protected by semaphores to avoid the overwriting of similar memory space. When the work over this critical section finishes the semaphore release it so that it cane be used by other processes while updating and reading the memory space.
Re: Don't know about critical section in c
In C programming language a critical section is a part of program code and which accesses a shared data structure or device. Critical section can not be accessed by multiple threads while execution of program. The critical section in C normally terminate within fixed amount of period. The Task, process of thread needs to wait for fixed period of time to access the Critical section of C.That is C language has some synchronization mechanism for the use of 'Critical section'.
Re: Don't know about critical section in c
Hello Friend,
Refer following program for critical section in C. Here I protected two processes from the critical section:
Quote:
while(First process is active)
{
InitializeCriticalSection(&chs);
EnterCriticalSection(&chs);
LeaveCriticalSection(&chs);
DeleteCriticalSection(&chs);
}
while (Second process is active)
{
InitializeCriticalSection(&chs);
EnterCriticalSection(&chs);
LeaveCriticalSection(&chs);
DeleteCriticalSection(&chs);
}
Re: Don't know about critical section in c
A critical section in C is normally used when a multithreaded program code try to update multiple c variables which are related to each other without conflicting changes to that particular data. In some conditions 'critical section' can be useful to ensure the resource which are shared. The example of this situation is that a printer could be accessible for only one process at a single time. I hope it will clear you doubts about critical section in c.
Re: Don't know about critical section in c
critical section in C language is piece of a process which must be indivisibly executed. critical sections must be uninterrupted by particular set of processes.This section must have specific termination time. Sometime the the thread or proceed need to wait for specific amount of time before accessing the critical section in C programming. The overwriting in the critical section is can be avoid by using the semaphores.