What do you mean by critical section in c?

Questions by vmannur

Showing Answers 1 - 9 of 9 Answers

preetin

  • Jul 16th, 2008
 

Critical section is the part of the code that can be assessed by multiple threads or processes at the same time.

In order to protect the overwriting of the same memory space, this part of the code is protected by use of semaphores. One process takes the semaphore and during this period, it cannot be executd by any other thread. When the work is finished, the semaphore is released so that other processes can use it to update the memory space or read from it.

critical section in c ,is a piece of code that accesses a shared resource (data structure or device) that must not be concurrently accessed by more than one thread/process of execution.
eg :-
while(1st thread is active)
{
Initialize CriticalSection
Enter Into CriticalSection
perform operation
Leave/release CriticalSection
Delete CriticalSection(1st thread)
}

while (2nd thread is active)
{
Initialize CriticalSection
Enter Into CriticalSection
perform 2nd thread operation
Leave/release CriticalSection
Delete CriticalSection(2nd thread)

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions