Author: Norman BullenNorman Bullen
Date: May 26, 2007 18:27
>>Critical sections are valid only between threads in the same process.
>>I've never checked myself how much faster they are supposed to be,
>>relative to semaphores, but critical sections would probably be the
>>right way to go.
>
>
> Thanks for the comment. After a bit of searching, it seems that
> Critical Sections are faster if they don't have to block.
>
> But the producer needs to be blocked when the buffer is already full,
> and the consumer needs to be blocked when the buffer is empty. This
> needs a counting semaphore.
>
> AIUI, a critical section will only block if another thread is
> executing its critical section, and there's no support for counting,
> so it doesn't seem to be suitable in this case.
>
The purpose of a Critical Section is to control access to variables that
maintain the state of the system; not for waiting for state changes. ...
|