this implement does not solve the problem.
still need pass the parameter in all functions. 
func (g *gls) run()    or    func run (g *gls) 

在 2019年6月19日星期三 UTC+8下午4:55:09,Jan Mercl写道:
>
> On Wed, Jun 19, 2019 at 10:41 AM hui zhang <fastf...@gmail.com 
> <javascript:>> wrote: 
>
> > but, very few document mention , how to do it as goroutine local storage 
> .  Can anyone give an example to solve my problem , refer the code I 
> attached? 
>
> Make the goroutine a method of a struct that contains any context the 
> goroutine needs. The data in the struct becomes your goroutine-local 
> storage. 
>
> type gls struct { id int } 
>
> func newG(id int) { 
>         g := &gls{id} 
>         go g.run() 
> } 
>
> func (g *gls) run() { fmt.Println(g.id) } 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/35de6b92-8240-4892-bc2e-d5cda3980582%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to