Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-29 Thread adithyasashasai
Yeah same problem. 

On Wednesday, May 27, 2020 at 8:03:35 AM UTC+5:30, Robert Engels wrote:
>
> You want the gls package referenced earlier. 
>
> Go doesn’t have it built in because the designers don’t like it or feel it 
> is necessary. You can find and read the GitHub issue that covers thread/go 
> local storage. 
>
> On May 26, 2020, at 8:04 PM, Jon Perryman  > wrote:
>
> 
>
> On Sun, May 24, 2020 at 11:05 PM > 
> wrote:
> > Yeah this works, but you can say this as workaround, what i really want 
> is, does native go support? if not why?
> >> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
> >> You may try to inspect this go package: https://github.com/jtolio/gls
>
> Each package has a set of global variables. Adding another set of globals 
> for each executing Goroutine would be too complex. Functions are not 
> specific to Goroutine, but a second global pool would require additional 
> considerations specific to goroutine vs main. 
>
> What is the drawback to passing the goroutine global variables as a struct 
> to each function? It's certainly far less overhead than the workaround and 
> it follows standard GO conventions. 
>
> 
> package main
>
> import (
> "fmt"
> "time"
> "sync"
> )
>
> func main() {
>
> go goroutine()
> go goroutine()
> go goroutine()
> go goroutine()
>
> time.Sleep(time.Second)
> fmt.Println("all done")
> }
>
> type Global struct {
> Id int
> Name string
> Cnt int
> }
>
> var goroutineCount int = 0
>
> func goroutine() {
> mutex := {}
> mutex.Lock()
> goroutineCount++
> mutex.Unlock()
> g := Global{
> Id : goroutineCount,
> Name : "some name",
> Cnt : 100,
> }
> g.Method1()
> }
>
> func (g *Global) Method1() {
> g.Method2()
> g.Cnt++
> fmt.Println("method1", g.Id, g.Name, g.Cnt)
> }
>
> func (g *Global) Method2() {
> g.Cnt++
> fmt.Println("method2", g.Id, g.Name, g.Cnt)
> }
> 
>
> Jon.
>
> -- 
> 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 golan...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAByJhJnn6uLbcM_JBBV%3DJewBQB5iztb23BYHAO98Bvf2nTkPUQ%40mail.gmail.com
>  
> 
> .
>
>

-- 
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/3c8efe53-c4fc-4fae-88cb-8c85c18c5204%40googlegroups.com.


Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-29 Thread adithyasashasai
Thanx. This i thought but i want context as "Global" struct, which i cant 
do.
Anyhow please refer https://github.com/golang/go/issues/21355


On Wednesday, May 27, 2020 at 6:34:24 AM UTC+5:30, Jon Perryman wrote:
>
>
> On Sun, May 24, 2020 at 11:05 PM > 
> wrote:
> > Yeah this works, but you can say this as workaround, what i really want 
> is, does native go support? if not why?
> >> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
> >> You may try to inspect this go package: https://github.com/jtolio/gls
>
> Each package has a set of global variables. Adding another set of globals 
> for each executing Goroutine would be too complex. Functions are not 
> specific to Goroutine, but a second global pool would require additional 
> considerations specific to goroutine vs main. 
>
> What is the drawback to passing the goroutine global variables as a struct 
> to each function? It's certainly far less overhead than the workaround and 
> it follows standard GO conventions. 
>
> 
> package main
>
> import (
> "fmt"
> "time"
> "sync"
> )
>
> func main() {
>
> go goroutine()
> go goroutine()
> go goroutine()
> go goroutine()
>
> time.Sleep(time.Second)
> fmt.Println("all done")
> }
>
> type Global struct {
> Id int
> Name string
> Cnt int
> }
>
> var goroutineCount int = 0
>
> func goroutine() {
> mutex := {}
> mutex.Lock()
> goroutineCount++
> mutex.Unlock()
> g := Global{
> Id : goroutineCount,
> Name : "some name",
> Cnt : 100,
> }
> g.Method1()
> }
>
> func (g *Global) Method1() {
> g.Method2()
> g.Cnt++
> fmt.Println("method1", g.Id, g.Name, g.Cnt)
> }
>
> func (g *Global) Method2() {
> g.Cnt++
> fmt.Println("method2", g.Id, g.Name, g.Cnt)
> }
> 
>
> Jon.
>

-- 
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/88474b1b-827e-4dcb-a56e-b942fafe71b8%40googlegroups.com.


Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-29 Thread adithyasashasai
This is issue i am referring to https://github.com/golang/go/issues/21355.

On Monday, May 25, 2020 at 10:21:19 PM UTC+5:30, Michael Jones wrote:
>
> Variables are names associated with values, values that can *vary*, that 
> is, can be changed. (Unlike constants, which are *constant* values.)
>
> In the beginning, all variables were global, and this was not good. 
>
>
> Then came local variables, ones *local* to a function, which came and 
> went as functions executed, and then block-scoped variables, ones local to 
> a particular begin...end or {...} block of code. This was seen as good, and 
> the people were urged to avoid global variables (and *goto* and other 
> ways of the past).
>
> Now, every combination of ways has a home in some language's culture: 
> *static* in C is a function-local global variable, Go style embraces 
> global variables for flag values, and there are local variables in 
> sophisticated assembly languages that never go to memory. 
>
> Now, what problem is it exactly that you want to solve?
>
> On Sun, May 24, 2020 at 11:06 PM > 
> wrote:
>
>> Yeah this works, but you can say this as workaround, what i really want 
>> is, does native go support? if not why?
>>
>> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
>>>
>>> You may try to inspect this go package: https://github.com/jtolio/gls
>>>
>> -- 
>> 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/3e71bdf8-3b99-4f47-9412-68cc50f69e84%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
>
> *Michael T. jonesmichae...@gmail.com *
>

-- 
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/b4794a2d-a044-4bb8-80f0-e35c089cfb2e%40googlegroups.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-29 Thread adithyasashasai
https://github.com/golang/go/issues/21355, this is the issue i am reffering 
to.

On Monday, May 25, 2020 at 10:38:31 PM UTC+5:30, Jake Montgomery wrote:
>
> On Sunday, May 24, 2020 at 3:46:54 PM UTC-4, adithya...@gmail.com wrote:
>>
>> if i am not wrong, Even the main itself is a go routine, which have 
>> global variables?
>>
>
> Perhaps you should describe a bit more what you mean? People seem to be 
> making assumptions that you meant something different that what you 
> actually said. Assuming you are referring to the main() function, then, no 
> it is not a goroutine, but it does run in a goroutine. However, main() doe 
> not "have" global variables. Can you give an exmaple of what you mean by 
> this?
>
> Global variables belong to the package, and are accessible from *any 
> *goroutine 
> in the package, if they are private, and from any goroutine anywhere if 
> they are public. 
>

-- 
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/4ace5c86-1895-4090-90ff-68be45454bdf%40googlegroups.com.


Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-26 Thread Robert Engels
You want the gls package referenced earlier. 

Go doesn’t have it built in because the designers don’t like it or feel it is 
necessary. You can find and read the GitHub issue that covers thread/go local 
storage. 

> On May 26, 2020, at 8:04 PM, Jon Perryman  wrote:
> 
> 
> 
> On Sun, May 24, 2020 at 11:05 PM  wrote:
> > Yeah this works, but you can say this as workaround, what i really want is, 
> > does native go support? if not why?
> >> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
> >> You may try to inspect this go package: https://github.com/jtolio/gls
> 
> Each package has a set of global variables. Adding another set of globals for 
> each executing Goroutine would be too complex. Functions are not specific to 
> Goroutine, but a second global pool would require additional considerations 
> specific to goroutine vs main. 
> 
> What is the drawback to passing the goroutine global variables as a struct to 
> each function? It's certainly far less overhead than the workaround and it 
> follows standard GO conventions. 
> 
> 
> package main
> 
> import (
> "fmt"
> "time"
> "sync"
> )
> 
> func main() {
> 
> go goroutine()
> go goroutine()
> go goroutine()
> go goroutine()
> 
> time.Sleep(time.Second)
> fmt.Println("all done")
> }
> 
> type Global struct {
> Id int
> Name string
> Cnt int
> }
> 
> var goroutineCount int = 0
> 
> func goroutine() {
> mutex := {}
> mutex.Lock()
> goroutineCount++
> mutex.Unlock()
> g := Global{
> Id : goroutineCount,
> Name : "some name",
> Cnt : 100,
> }
> g.Method1()
> }
> 
> func (g *Global) Method1() {
> g.Method2()
> g.Cnt++
> fmt.Println("method1", g.Id, g.Name, g.Cnt)
> }
> 
> func (g *Global) Method2() {
> g.Cnt++
> fmt.Println("method2", g.Id, g.Name, g.Cnt)
> }
> 
> 
> Jon.
> -- 
> 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/CAByJhJnn6uLbcM_JBBV%3DJewBQB5iztb23BYHAO98Bvf2nTkPUQ%40mail.gmail.com.

-- 
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/266115A4-84BA-4131-81BD-C49DC74ABA80%40ix.netcom.com.


Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-26 Thread Jon Perryman
On Sun, May 24, 2020 at 11:05 PM  wrote:
> Yeah this works, but you can say this as workaround, what i really want
is, does native go support? if not why?
>> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
>> You may try to inspect this go package: https://github.com/jtolio/gls

Each package has a set of global variables. Adding another set of globals
for each executing Goroutine would be too complex. Functions are not
specific to Goroutine, but a second global pool would require additional
considerations specific to goroutine vs main.

What is the drawback to passing the goroutine global variables as a struct
to each function? It's certainly far less overhead than the workaround and
it follows standard GO conventions.


package main

import (
"fmt"
"time"
"sync"
)

func main() {

go goroutine()
go goroutine()
go goroutine()
go goroutine()

time.Sleep(time.Second)
fmt.Println("all done")
}

type Global struct {
Id int
Name string
Cnt int
}

var goroutineCount int = 0

func goroutine() {
mutex := {}
mutex.Lock()
goroutineCount++
mutex.Unlock()
g := Global{
Id : goroutineCount,
Name : "some name",
Cnt : 100,
}
g.Method1()
}

func (g *Global) Method1() {
g.Method2()
g.Cnt++
fmt.Println("method1", g.Id, g.Name, g.Cnt)
}

func (g *Global) Method2() {
g.Cnt++
fmt.Println("method2", g.Id, g.Name, g.Cnt)
}


Jon.

-- 
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/CAByJhJnn6uLbcM_JBBV%3DJewBQB5iztb23BYHAO98Bvf2nTkPUQ%40mail.gmail.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-25 Thread Jake Montgomery
On Sunday, May 24, 2020 at 3:46:54 PM UTC-4, adithya...@gmail.com wrote:
>
> if i am not wrong, Even the main itself is a go routine, which have global 
> variables?
>

Perhaps you should describe a bit more what you mean? People seem to be 
making assumptions that you meant something different that what you 
actually said. Assuming you are referring to the main() function, then, no 
it is not a goroutine, but it does run in a goroutine. However, main() doe 
not "have" global variables. Can you give an exmaple of what you mean by 
this?

Global variables belong to the package, and are accessible from *any *goroutine 
in the package, if they are private, and from any goroutine anywhere if 
they are public. 

-- 
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/749251f0-513f-4e6b-9636-b1e596daadbb%40googlegroups.com.


Re: [go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-25 Thread Michael Jones
Variables are names associated with values, values that can *vary*, that
is, can be changed. (Unlike constants, which are *constant* values.)

In the beginning, all variables were global, and this was not good.


Then came local variables, ones *local* to a function, which came and went
as functions executed, and then block-scoped variables, ones local to a
particular begin...end or {...} block of code. This was seen as good, and
the people were urged to avoid global variables (and *goto* and other ways
of the past).

Now, every combination of ways has a home in some language's culture:
*static* in C is a function-local global variable, Go style embraces global
variables for flag values, and there are local variables in sophisticated
assembly languages that never go to memory.

Now, what problem is it exactly that you want to solve?

On Sun, May 24, 2020 at 11:06 PM  wrote:

> Yeah this works, but you can say this as workaround, what i really want
> is, does native go support? if not why?
>
> On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
>>
>> You may try to inspect this go package: https://github.com/jtolio/gls
>>
> --
> 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/3e71bdf8-3b99-4f47-9412-68cc50f69e84%40googlegroups.com
> 
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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/CALoEmQzv8DpS%3DBG-peZj3%3D2oht%2BD%3DOoipyiK3gDGo7gaswQPDA%40mail.gmail.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-25 Thread adithyasashasai
Yeah this works, but you can say this as workaround, what i really want is, 
does native go support? if not why?

On Monday, May 25, 2020 at 7:57:17 AM UTC+5:30, tokers wrote:
>
> You may try to inspect this go package: https://github.com/jtolio/gls
>

-- 
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/3e71bdf8-3b99-4f47-9412-68cc50f69e84%40googlegroups.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-24 Thread tokers
You may try to inspect this go package: https://github.com/jtolio/gls

-- 
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/6cb0288c-8dda-4b24-82ca-d41c28b7ddca%40googlegroups.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-24 Thread adithyasashasai
if i am not wrong, Even the main itself is a go routine, which have global 
variables?


On Monday, May 25, 2020 at 12:23:49 AM UTC+5:30, Saied Seghatoleslami wrote:
>
> Variable scope is a textual (special if you like) concept.   Go routines 
> are a temporal concept.   Does it make sense to think about a global 
> variable in this way? 

-- 
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/58ead137-5e3e-4c37-8f35-eed20188da66%40googlegroups.com.