Hard question about Critical section - in C++ ....
-
Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O
-
Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O
There are numerous good articles about this: Check Here.[^] ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O
yanshof wrote:
Can someone explain the main idea of the critical section in this case ?
See here.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
yanshof wrote:
Can someone explain the main idea of the critical section in this case ?
See here.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O
yanshof wrote:
- i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block.
I'm not sure I follow.. A CRITICAL_SECTION variable is an opaque object which holds a lock state. It's not a handle to anything, like mutexes are (they are kernel objects). I'm not sure what you mean by block, but I'm going to assume it's a body of code such as
{ ... }
. A critical section is not automatically associated with such a block. The state of the critical section object is determined by the Enter/Leave functions, and can span over any number of blocks.-- 100% natural. No superstitious additives.
-
Hello, When you define in some function a critical section you define a critical section block or variable ? :confused::confused::confused: I will explain - when some thread get to this Critical section and the Critical section is lock - so this thread will go sleep until this Critical section will be unlock and the event will be called to rise up. But my problem (or my bad understanding) is about the block of the critical section - i think that the critical section is only to block thread and make the thread sleep and have no direct connection to the block - but some other thought is that the critical section is define only on block. Can someone explain the main idea of the critical section in this case ? Thanks on any help. :-O
A critical section is a small section of code that requires exclusive access to some shared resource before the code can execute. To protect that section of code we need to encapsulate that code in EnterCriticalSection and LeaveCriticalSection function call. Better avoid using 'block' terminology.
-
A critical section is a small section of code that requires exclusive access to some shared resource before the code can execute. To protect that section of code we need to encapsulate that code in EnterCriticalSection and LeaveCriticalSection function call. Better avoid using 'block' terminology.
-
I read those both and i still have the same question. My question will not appear in there.... like i said this is hard question...
yanshof wrote:
I read those both and i still have the same question.
Why? What part did you not understand?
yanshof wrote:
My question will not appear in there....
Maybe not directly, but you can easily infer the answer.
yanshof wrote:
When you define in some function a critical section you define a critical section block or variable ?
A critical section is a block of code (that can contain variables).
yanshof wrote:
Can someone explain the main idea of the critical section in this case ?
The link I provided you explained this in detail.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb