On Thu, Feb 21, 2019 at 1:10 PM Serhat Şevki Dinçer <jfcga...@gmail.com> wrote:
>
> Burak, I think you dont get the potential of the suggesred directives.
>
> You can be interested in waitepty(ch) for example when:
> - you have direct control of who is pushing and pulling on it, and you know 
> what an empty buffer means
> buffer could be "things to do or process", and you have a very easy-to-setup 
> observer to alert some routine that:
> - you are out of job, or
> - you have too many to process

I see. However, I still don't think channel is a good abstraction for
this. A customized solution, possibly without using channels is much
better suited I think.

>
> Also what you suggest as raciness is irrelevant:
>
> for {
>   x := <- ch {
>     // here, do you have a guarantee that you can put x back to the channel ??

No, but you have a guarantee that ch was read, and what you read is
what was written.

>   }
> }
>
> On Thursday, February 21, 2019 at 10:57:43 PM UTC+3, Burak Serdar wrote:
>>
>> You can implement waitempty(ch) without a race condition. However, any
>> scenario in which you use waitempty(ch) would have a race condition,
>> because the moment it returns there is no guarantee on the state of
>> the channel. So in a piece of code like this:
>>
>> waitempty(ch)
>> post
>>
>>
>> the only guarantee you have is that when 'post' is running, ch was
>> empty at least once since waitempty was called.
>>
>> This code:
>>
>> for {
>>   if waitempty(ch) {
>>     ...
>>   }
>> }
>>
>> is racy, because when you go into the if block, you have no idea how
>> many times ch was empty.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to