Hi Ian,

I actually made a typo in the code that I should have called defer Unlock() 
rather than Unlock directly at line 21. There shouldn't be any other race.

This is the fix, with some changes to better demonstrate the intention.
https://play.golang.org/p/yKd-81-cFY

The idea to use Gosched here is to yield to other gorountine which could 
potentially enqueue more fetch requests before making the remote call. 
(This was mainly inspired by what facebook did on a library on node.js, 
https://github.com/facebook/dataloader, that they schedule the batched 
remote call at the end of the current event loop).

But after reading the older posts here, supporting custom scheduling 
behavior is not a feature for the go runtime. So I would say this is a bad 
use of Gosched.

Thanks,
-bgd

On Sunday, July 10, 2016 at 8:20:24 PM UTC-4, Ian Lance Taylor wrote:
>
> On Sun, Jul 10, 2016 at 1:03 PM,  <bigd...@gmail.com <javascript:>> 
> wrote: 
> > I came up with piece of code to use runtime.Gosched for batching 
> multiple 
> > requests  "auto-magically" from the client side. 
> > 
> > https://play.golang.org/p/QK1wbtgVLf 
> > 
> > It works and it is actually very useful for many scenarios, but I wonder 
> if 
> > this is a good/bad way of doing stuff like this, or is there a 
> better/more 
> > proper way to do it. 
> > 
> > (I know the actual scheduling behavior is not defined, but I don't need 
> the 
> > request to be strictly batched, just some degree of batching better than 
> > none.) 
>
> Your code looks pretty racy to me.  You should run it under the race 
> detector and fix any problems you discover (see 
> https://blog.golang.org/race-detector).  If you do that I think the 
> calls to runtime.Gosched will be pointless. 
>
> Ian 
>

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