views:

69

answers:

3

Please can some one briefly tell me with example what does the means of critical section? in simple language

+1  A: 

A critical section is a section of code that needs to be executed without outside interference - i.e. without another thread potentially affecting/being affected by "intermediate" states within the section.

For instance, a reservation system might have a critical section when reserving something in that it needs to both check to see if the item is available and then mark it as no longer available, without some other attempt at reserving the room changing that status in the middle.

Thus, the critical section of a piece of code is a place where only one thread of execution is allowed to be at a time, to prevent things like race conditions.

Amber
A: 

A critical section wraps that portion of your code where shared data is being modified. The monitor ensures that only one thread at a time enters.

duffymo
+1  A: 

For an example (in C#), check this out.

Zaki