2018-05-04 19:32 GMT+03:00 Ian Lance Taylor <i...@golang.org>:

> On Fri, May 4, 2018 at 2:00 AM,  <bambys...@gmail.com> wrote:
> >
> > And I want to modify the worker thread like this:
> >
> > for {
> >     select {
> >     case wi := <- work_ch:
> >         self.do_the_work(wi)
> >     case <-self.idle_request:
> >         self.idle_response <- true
> >     }
> > }
> >
> > However this last snippet of code does not work because the cases within
> the
> > select statement are randomly chosen when both channels are ready so I
> have
> > no guarantee that the first case is executed first.
>
> You also have no guarantee that a request won't arrive on work_ch a
> nanosecond after the worker is told to go idle, but presumably that is
> not a problem.


In fact I have that guarantee because the supplier thread is a single
goroutine and it guarantees that there would be no items on the work_ch
after the idle state is requested and before the worker responded. Also the
worker is never requested to stop, it is only requested to report that it
has completed all the work and it is now idle.


>   If you need to ensure that some set of requests is
> completed before the workers go idle, then you need some sort of
> timestamp on jobs, and you should tell the worker to go idle as of a
> specific timestamp.  Once you have that, when the worker sees an idle
> request, with an idle timestamp, it can keep accepting work requests
> until it sees one with a later timestamp.  It can then report that it
> is going idle, and sleep until it is woken up, holding onto the next
> job that it will start doing when it wakes up.
>
> Ian
>



-- 
  Andriy

-- 
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