Re: [go-nuts] How to run a go method on multiple cores ?
Sorry for the much delayed response. I have not had enough time lately! * Nitish Saboo [190508 05:48]: > "Do you mean "log/syslog" from the standard library? What does > initialize do?" > > >>I have installed syslog-ng parser on my Linux box and I am planning you > use syslog-ng parser and wanted to initialise it's engine for parsing the > data. There are two general aspects to your problem that are unclear. First, what do you mean by "syslog-ng engine" or "syslog-ng parser" and how does it run from within the C code? Second, what underlying problem are you trying to solve that you believe running two of these "engines" on different CPUs will solve? In previous messages, you had just said "syslog engine" and gave no indication that non-Go code was involved. Clarifying in your last message that you are using C code with cgo is a good first step, but we need more information. I was thinking of three different things you might mean by "syslog engine". The first is something that accepted messages from Go code in this program and sent them to an external syslog daemon to be logged. The second is something running in this program that acted as a replacement for a standard syslog daemon. The third is something that takes the output of a syslog daemon (the log files) and parses them to allow analysis. A fourth possibility comes to mind, now that you have specified that you are using syslog-ng through C code: a syslog-ng plugin that is somehow called by an external syslog-ng daemon during its handling of messages to be logged. This fourth possibility now seems to be the most likely, based on your last message, so I will focus my questions in this direction. Does the initialize_engine function return after the initialization completes, before any actual processing occurs, or does it keep running until that "engine" has completed all its processing? If the former, how does the "engine" ask your program to perform some processing? Is the communication with the syslog-ng daemon hidden in a library linked to your program, and the library invokes callbacks on a C function that you provided, or does the library give you an open socket that you read and write to handle processing requests from the daemon? Is the library multi-thread aware? Does it create its own threads? Regardless of which of the four possibilities (or others I haven't thought of) is appropriate, the important question is how does the code in initialize_engine arrange for processing of requests? Does it spawn a new process? Does it create a new thread? Does it use C callback functions? Does it use file descriptors, such as Unix sockets? The second aspect, _why_ are you trying to run each engine on its own CPU, is one that others in this thread have asked about, but your answer has been "Yes, I want to run each engine on a separate CPU", which does not give the type of information that helps us give you a good answer to your question. You might be trying to provide fail-over, or load balancing, or something else. Do you really need to lock each "engine" on its own CPU, or is having two concurrently running "engines", letting the Go scheduler take care of the details of OS threads and CPUs, sufficient? Keep in mind that when the function invoked as the go routine terminates, Go no longer "knows" about the go routine. Any stack allocated by Go for that go routine will be freed, and no further scheduling of that sequence of instructions will occur. If the go routine only calls Go code, this is simple enough, but when the go routine calls C code which creates its own threads, you need to have a deeper understanding of both cgo and the Go scheduler. So, the LockOSThread call in the following might be completely superfluous: go func() { runtime.LockOSThread() C.initialize_engine(some, arguments) }() It will lock the go routine onto a single OS thread for the duration of initialize_engine, but it may not have any effect on whatever "engine" was started by initialize_engine after initialize_engine returns. In fact, if initialize_engine, as part of creating the "engine", creates a new OS thread, then the go routines themselves may be completely superfluous, and something like this sequential code: C.initialize_engine(some, arguments) // start first engine C.initialize_engine(other, different_arguments) // start second engine may be perfectly suitable. In summary, for us to help you, you need to answer these two questions: 1. What problem are you trying to solve by locking each "engine" to its own CPU (or thread or go routine)? (Hint: "running two instances of engine" is not a sufficient answer.) 2. How does the code in initialize_engine change the execution state (e.g. threads and processes) and how does the Go program communicate with the "engine" after it is started? ...Marvin -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group
Re: [go-nuts] How to run a go method on multiple cores ?
Apologies Marvin. On Thu, May 9, 2019 at 6:53 PM Marvin Renich wrote: > * Nitish Saboo [190508 05:48]: > > Please remove me from the CC on this thread; I am subscribed to the > list. I explicitly set Reply-To, which was not respected, and now I am > getting duplicates of every mail, with one copy in my personal mail and > one copy in my list mail folder. In general, it is a very good > assumption that someone posting to the list, unless he/she explicitly says > otherwise, is subscribed to the list and does not need an explicit CC. > In some cases, like for me, not only is this not needed, but it is an > unwanted distraction. > > I intend to, but have not yet had time, reply to Nitish Saboo with some > questions that will help him provide the right information so that we > may give him some more help. It may be several days before I can do so. > > Thank you...Marvin > > -- > 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/20190509132302.wybkhuf3rfrgedeb%40basil.wdw > . > 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CALjMrq6pdVkRAXu04R884RsRoB%3DvYxw7ycOhiJyUzLpb-4hBsQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
* Nitish Saboo [190508 05:48]: Please remove me from the CC on this thread; I am subscribed to the list. I explicitly set Reply-To, which was not respected, and now I am getting duplicates of every mail, with one copy in my personal mail and one copy in my list mail folder. In general, it is a very good assumption that someone posting to the list, unless he/she explicitly says otherwise, is subscribed to the list and does not need an explicit CC. In some cases, like for me, not only is this not needed, but it is an unwanted distraction. I intend to, but have not yet had time, reply to Nitish Saboo with some questions that will help him provide the right information so that we may give him some more help. It may be several days before I can do so. Thank you...Marvin -- 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/20190509132302.wybkhuf3rfrgedeb%40basil.wdw. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
I believe you can use lockOSThread to pin a processor to the current thread, then use native code to pin the thread to a particular processor, change its priority, etc. I haven’t tried it but I see no reason it wouldn’t work - similar to how it’s not supported in Java but you can still do it - watch out for priority inversion and scheduling deadlocks ! > On May 9, 2019, at 3:31 AM, Nitish Saboo wrote: > > Hi Kurtis, > > Thanks for the clarification .initialize_engine() is a C code and is being > called from go method 'initialize()'. > If you see my reply 2 mails before, 'initialize_engine()` method starts a > syslog-ng engine but does not return the instance of it. > And therefore there was a confusion if calling 'initialize_engine' twice is > actually instantiating two independent syslog-ng instances or not. > > Thanks > > >> On Thu, May 9, 2019 at 11:12 AM Kurtis Rader wrote: >>> On Wed, May 8, 2019 at 10:17 PM Nitish Saboo >>> wrote: >> >>> Yes, I want (exactly) two instances of syslog-ng engines running since I >>> initialised the engine twice.And I guess it is possible only when the >>> syslog-ng engines are running on two different processors.I might be wrong >>> here, please correct me if my understanding is not right. >>> My goal right now is how to verify if two independent syslog-ng engines are >>> getting initialised or not ? >>> Once this verification is done, Can we hook instance 'a' to syslog-ng >>> engine on processor 'a' and instance 'b' to syslog-ng engine on processor >>> 'b'. >> >> There may be a human language barrier here in as much as my native language >> is English and I suspect your native language is something else. Whether or >> not you instantiate two distinct syslog-ng engines is unrelated to which >> CPUs (processors) each runs on. There is no way, in general, for the Go >> scheduler to know which CPU a goroutine is running on. Nor is there any way >> to bind a goroutine to a specific CPU as far as I know. You could (in >> theory) create two distinct instances of the syslog-ng engine and they could >> still execute on the same CPU. If or no other reason than that your system >> only has a single CPU core available for your process. >> >> > I hope I am able to clarify my thinking here. >> >> No, sorry, you have not. If anything every reply you make increases the >> confusion about what you are trying to do. If your `initialize_engine()` >> method always instantiates, and returns, a new instance of the "syslog-ng" >> engine then the two Go objects initialized by that call will be two >> independent instances of that engine. Assuming, of course, that your >> syslog-ng engine does not share state between distinct `initialize_engine()` >> calls. >> >> -- >> Kurtis Rader >> Caretaker of the exceptional canines Junior and Hank > > -- > 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/CALjMrq7jyZmDEwTxbQ-m-WUubP-A2_QWw-8UZhUbi%2BcLd1wpOQ%40mail.gmail.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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2891AEAD-B5DB-4D77-9D78-716EF02A14AC%40ix.netcom.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Kurtis, Thanks for the clarification .*i*nitialize_engine() is a C code and is being called from go method 'initialize()'. If you see my reply 2 mails before, '*i*nitialize_engine()` method starts a syslog-ng engine but does not return the instance of it. And therefore there was a confusion if calling '*i*nitialize_engine' twice is actually instantiating two independent syslog-ng instances or not. Thanks On Thu, May 9, 2019 at 11:12 AM Kurtis Rader wrote: > On Wed, May 8, 2019 at 10:17 PM Nitish Saboo > wrote: > >> Yes, I want (exactly) two instances of syslog-ng engines running since I >> initialised the engine twice.And I guess it is possible only when the >> syslog-ng engines are running on two different processors.I might be wrong >> here, please correct me if my understanding is not right. >> My goal right now is how to verify if two independent syslog-ng engines >> are getting initialised or not ? >> Once this verification is done, Can we hook instance 'a' to syslog-ng >> engine on processor 'a' and instance 'b' to syslog-ng engine on processor >> 'b'. >> > > There may be a human language barrier here in as much as my native > language is English and I suspect your native language is something else. > Whether or not you instantiate two distinct syslog-ng engines is unrelated > to which CPUs (processors) each runs on. There is no way, in general, for > the Go scheduler to know which CPU a goroutine is running on. Nor is there > any way to bind a goroutine to a specific CPU as far as I know. You could > (in theory) create two distinct instances of the syslog-ng engine and they > could still execute on the same CPU. If or no other reason than that your > system only has a single CPU core available for your process. > > > I hope I am able to clarify my thinking here. > > No, sorry, you have not. If anything every reply you make increases the > confusion about what you are trying to do. If your `*initialize_engine()` > method always instantiates, and returns, a new instance of the "syslog-ng" > engine then the two Go objects initialized by that call will be two > independent instances of that engine. Assuming, of course, that your > syslog-ng engine does not share state between distinct `**initialize_engine()` > calls.* > > -- > Kurtis Rader > Caretaker of the exceptional canines Junior and Hank > -- 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/CALjMrq7jyZmDEwTxbQ-m-WUubP-A2_QWw-8UZhUbi%2BcLd1wpOQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
On Wed, May 8, 2019 at 10:17 PM Nitish Saboo wrote: > Yes, I want (exactly) two instances of syslog-ng engines running since I > initialised the engine twice.And I guess it is possible only when the > syslog-ng engines are running on two different processors.I might be wrong > here, please correct me if my understanding is not right. > My goal right now is how to verify if two independent syslog-ng engines > are getting initialised or not ? > Once this verification is done, Can we hook instance 'a' to syslog-ng > engine on processor 'a' and instance 'b' to syslog-ng engine on processor > 'b'. > There may be a human language barrier here in as much as my native language is English and I suspect your native language is something else. Whether or not you instantiate two distinct syslog-ng engines is unrelated to which CPUs (processors) each runs on. There is no way, in general, for the Go scheduler to know which CPU a goroutine is running on. Nor is there any way to bind a goroutine to a specific CPU as far as I know. You could (in theory) create two distinct instances of the syslog-ng engine and they could still execute on the same CPU. If or no other reason than that your system only has a single CPU core available for your process. > I hope I am able to clarify my thinking here. No, sorry, you have not. If anything every reply you make increases the confusion about what you are trying to do. If your `*initialize_engine()` method always instantiates, and returns, a new instance of the "syslog-ng" engine then the two Go objects initialized by that call will be two independent instances of that engine. Assuming, of course, that your syslog-ng engine does not share state between distinct `**initialize_engine()` calls.* -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- 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/CABx2%3DD_s54b%3DUcprekRMWXGZvRv%3D51E6XsgM8u9yd3XQHtTZ%3DQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Michael, Yes, I want (exactly) two instances of syslog-ng engines running since I initialised the engine twice.And I guess it is possible only when the syslog-ng engines are running on two different processors.I might be wrong here, please correct me if my understanding is not right. My goal right now is how to verify if two independent syslog-ng engines are getting initialised or not ? Once this verification is done, Can we hook instance 'a' to syslog-ng engine on processor 'a' and instance 'b' to syslog-ng engine on processor 'b'. I hope I am able to clarify my thinking here. Thanks On Thu, May 9, 2019 at 4:01 AM Michael Jones wrote: > Can you share a little more of your motivation for saying: “I want two > instances of syslog-ng engine running on two different processors.” > > Do you mean (minimum) that you want two independent instances, or > (maximum) that you want to prove that there are two instances, two physical > processors, and that at no time does processor “a” execute code on behalf > of instance “b” and likewise for processor “b” and instance “a”, (or > something else completely). > > This “proof” idea seems very unusual but also seems to be what you want. > Maybe it is not. That’s why it might be good to share more of your thinking > and not just the conclusion. > > The natural thing in most every situation with modern CPUs, OSs, and non > hard real-time applications, is just having enough total CPU resources for > the mix of work and enough independence (concurrency opportunity) in the > application so that the load can be magically balanced. > > If this is not enough for you then you must have special circumstances. > > On Wed, May 8, 2019 at 2:47 AM Nitish Saboo > wrote: > >> Hi Marvin, >> >> Thanks for your response. >> >> "Do you mean "log/syslog" from the standard library? What does >> initialize do?" >> >> >>I have installed syslog-ng parser on my Linux box and I am planning you >> use syslog-ng parser and wanted to initialise it's engine for parsing the >> data. >> >> so initialise() method in my Go code calls C code that is wrapper around >> syslog-ng C header files.So ,I am making use of cgo >> >> *Following is my Go code:* >> >> func (obj Syslogparser) initialise{ >> >> X := C.CString(obj.X) >> defer C.free(unsafe.Pointer(X)) >> Y := C.CString(obj.Y) >> defer C.free(unsafe.Pointer(Y)) >> C.initialize_engine(X, Y, >> (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo))); >> } >> >> *And following is my C method 'initialize_engine':* >> >> int initialize_engine(const gchar* X, const gchar* Y, key_value_cb cb) // >> cb is callback function >> { >> // does some operation for initialising the engine of syslog-ng parser >> return 0; >> } >> >> 1)I want two instances of syslog-ng engine running on two different >> processors.How can I achieve this? >> >> 2)I made the following change : >> >> func main { >> var obj1 Syslogparser = initalize() // This initialises syslog-ng >> engine.call >> to a C library via cgo >> var obj2 Syslogparser// Not a package-level variable >> obj1.ParseMessage(program,msg)// this will parse the data and get the >> result >> if result["Z"] == "unknown"{ // On the basis of this result I want to >> initialise a new engine >> go func() { >> opts := Syslog{} >> obj2 = initalize() //call to a C library via cgo >> obj2.ReloadPatternDB(opts) //call to a C library via cgo >> obj2.ParseMessage(program, msg) //call to a C library via cgo >> }() >> } >> } >> >> Will this initialise two different syslog-ng engines for me ? >> >> 3)I understand goroutines are not OS threads and they just run on OS >> threads.Can we extract the process id of the running syslog-ng engines >> within the go routine where it spawned the syslog-ng engine ? >> >> Thanks >> >> >> On Wed, May 8, 2019 at 3:01 AM Marvin Renich wrote: >> >>> * Nitish Saboo [190507 14:07]: >>> > Thanks Michel for your detailed response. >>> > I am initialising the syslog engine. >>> >>> Do you mean "log/syslog" from the standard library? What does >>> initialize do? >>> >>> > var obj1 parser = initalize() >>> > var obj2 parser >>> > go func() { >>> > obj2 = initalize() >>> > }() >>> >>> You have initialized obj1, then you create a go routine that initializes >>> obj2. Assuming the initialization step takes a relatively short amount >>> of time and terminates, and does not itself create another go routine, >>> obj2 is not "on another go routine" (or thread or CPU or anything else). >>> It is simply another variable whose value was assigned by a different go >>> routine, but that go routine terminated immediately after obj2 was given >>> its value. >>> >>> Note that obj2 is a variable, not a running function; it is not >>> associated with a specific go routine, at least not in the sense that >>> you appear to be thinking. If obj2 is declared at the package level, >>> than any function in the package can reference it regardless of the go >>> routine in which that function is running. >>>
Re: [go-nuts] How to run a go method on multiple cores ?
Can you share a little more of your motivation for saying: “I want two instances of syslog-ng engine running on two different processors.” Do you mean (minimum) that you want two independent instances, or (maximum) that you want to prove that there are two instances, two physical processors, and that at no time does processor “a” execute code on behalf of instance “b” and likewise for processor “b” and instance “a”, (or something else completely). This “proof” idea seems very unusual but also seems to be what you want. Maybe it is not. That’s why it might be good to share more of your thinking and not just the conclusion. The natural thing in most every situation with modern CPUs, OSs, and non hard real-time applications, is just having enough total CPU resources for the mix of work and enough independence (concurrency opportunity) in the application so that the load can be magically balanced. If this is not enough for you then you must have special circumstances. On Wed, May 8, 2019 at 2:47 AM Nitish Saboo wrote: > Hi Marvin, > > Thanks for your response. > > "Do you mean "log/syslog" from the standard library? What does > initialize do?" > > >>I have installed syslog-ng parser on my Linux box and I am planning you > use syslog-ng parser and wanted to initialise it's engine for parsing the > data. > > so initialise() method in my Go code calls C code that is wrapper around > syslog-ng C header files.So ,I am making use of cgo > > *Following is my Go code:* > > func (obj Syslogparser) initialise{ > > X := C.CString(obj.X) > defer C.free(unsafe.Pointer(X)) > Y := C.CString(obj.Y) > defer C.free(unsafe.Pointer(Y)) > C.initialize_engine(X, Y, > (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo))); > } > > *And following is my C method 'initialize_engine':* > > int initialize_engine(const gchar* X, const gchar* Y, key_value_cb cb) // > cb is callback function > { > // does some operation for initialising the engine of syslog-ng parser > return 0; > } > > 1)I want two instances of syslog-ng engine running on two different > processors.How can I achieve this? > > 2)I made the following change : > > func main { > var obj1 Syslogparser = initalize() // This initialises syslog-ng engine.call > to a C library via cgo > var obj2 Syslogparser// Not a package-level variable > obj1.ParseMessage(program,msg)// this will parse the data and get the > result > if result["Z"] == "unknown"{ // On the basis of this result I want to > initialise a new engine > go func() { > opts := Syslog{} > obj2 = initalize() //call to a C library via cgo > obj2.ReloadPatternDB(opts) //call to a C library via cgo > obj2.ParseMessage(program, msg) //call to a C library via cgo > }() > } > } > > Will this initialise two different syslog-ng engines for me ? > > 3)I understand goroutines are not OS threads and they just run on OS > threads.Can we extract the process id of the running syslog-ng engines > within the go routine where it spawned the syslog-ng engine ? > > Thanks > > > On Wed, May 8, 2019 at 3:01 AM Marvin Renich wrote: > >> * Nitish Saboo [190507 14:07]: >> > Thanks Michel for your detailed response. >> > I am initialising the syslog engine. >> >> Do you mean "log/syslog" from the standard library? What does >> initialize do? >> >> > var obj1 parser = initalize() >> > var obj2 parser >> > go func() { >> > obj2 = initalize() >> > }() >> >> You have initialized obj1, then you create a go routine that initializes >> obj2. Assuming the initialization step takes a relatively short amount >> of time and terminates, and does not itself create another go routine, >> obj2 is not "on another go routine" (or thread or CPU or anything else). >> It is simply another variable whose value was assigned by a different go >> routine, but that go routine terminated immediately after obj2 was given >> its value. >> >> Note that obj2 is a variable, not a running function; it is not >> associated with a specific go routine, at least not in the sense that >> you appear to be thinking. If obj2 is declared at the package level, >> than any function in the package can reference it regardless of the go >> routine in which that function is running. >> >> > if obj1 engine fails: >> > go func() { >> > obj2.ReloadPattern(opts) >> > }() >> > >> > My question is, will obj2.ReloadPattern reload the pattern on the second >> > syslog-engine , how can I verify that?Because I am not maintaining the >> > engine info. I am just having the parser object. >> > Will parser object obj2 go and reload the respective syslog engine that >> was >> > initialised by it? I guess yes, but still need clarification on this . >> >> A new go routine will be created (possibly unnecessarily, but you don't >> give enough information), and the ReloadPattern method of obj2 will be >> invoked in that go routine. When ReloadPattern terminates, the go >> routine will also terminate. obj2 is still a package-level variable (or >> associated with
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Marvin, Thanks for your response. "Do you mean "log/syslog" from the standard library? What does initialize do?" >>I have installed syslog-ng parser on my Linux box and I am planning you use syslog-ng parser and wanted to initialise it's engine for parsing the data. so initialise() method in my Go code calls C code that is wrapper around syslog-ng C header files.So ,I am making use of cgo *Following is my Go code:* func (obj Syslogparser) initialise{ X := C.CString(obj.X) defer C.free(unsafe.Pointer(X)) Y := C.CString(obj.Y) defer C.free(unsafe.Pointer(Y)) C.initialize_engine(X, Y, (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo))); } *And following is my C method 'initialize_engine':* int initialize_engine(const gchar* X, const gchar* Y, key_value_cb cb) // cb is callback function { // does some operation for initialising the engine of syslog-ng parser return 0; } 1)I want two instances of syslog-ng engine running on two different processors.How can I achieve this? 2)I made the following change : func main { var obj1 Syslogparser = initalize() // This initialises syslog-ng engine.call to a C library via cgo var obj2 Syslogparser// Not a package-level variable obj1.ParseMessage(program,msg)// this will parse the data and get the result if result["Z"] == "unknown"{ // On the basis of this result I want to initialise a new engine go func() { opts := Syslog{} obj2 = initalize() //call to a C library via cgo obj2.ReloadPatternDB(opts) //call to a C library via cgo obj2.ParseMessage(program, msg) //call to a C library via cgo }() } } Will this initialise two different syslog-ng engines for me ? 3)I understand goroutines are not OS threads and they just run on OS threads.Can we extract the process id of the running syslog-ng engines within the go routine where it spawned the syslog-ng engine ? Thanks On Wed, May 8, 2019 at 3:01 AM Marvin Renich wrote: > * Nitish Saboo [190507 14:07]: > > Thanks Michel for your detailed response. > > I am initialising the syslog engine. > > Do you mean "log/syslog" from the standard library? What does > initialize do? > > > var obj1 parser = initalize() > > var obj2 parser > > go func() { > > obj2 = initalize() > > }() > > You have initialized obj1, then you create a go routine that initializes > obj2. Assuming the initialization step takes a relatively short amount > of time and terminates, and does not itself create another go routine, > obj2 is not "on another go routine" (or thread or CPU or anything else). > It is simply another variable whose value was assigned by a different go > routine, but that go routine terminated immediately after obj2 was given > its value. > > Note that obj2 is a variable, not a running function; it is not > associated with a specific go routine, at least not in the sense that > you appear to be thinking. If obj2 is declared at the package level, > than any function in the package can reference it regardless of the go > routine in which that function is running. > > > if obj1 engine fails: > > go func() { > > obj2.ReloadPattern(opts) > > }() > > > > My question is, will obj2.ReloadPattern reload the pattern on the second > > syslog-engine , how can I verify that?Because I am not maintaining the > > engine info. I am just having the parser object. > > Will parser object obj2 go and reload the respective syslog engine that > was > > initialised by it? I guess yes, but still need clarification on this . > > A new go routine will be created (possibly unnecessarily, but you don't > give enough information), and the ReloadPattern method of obj2 will be > invoked in that go routine. When ReloadPattern terminates, the go > routine will also terminate. obj2 is still a package-level variable (or > associated with whatever scope in which it was declared). > > > Since I was not able to identify the exact syslog engine, I was trying to > > identify it using the processor. > > Since you don't give enough information, I'm going to take some guesses, > which could be completely wrong. I am guessing that you are using the > standard library "log/syslog" package, and you have encapsulated the > result of either NewLogger, New, or Dial from that package in your own > structure which is returned by initialize. Your structure has > additional fields and methods, and some of the methods call appropriate > methods on the value obtained from the syslog package. > > I don't know what your structure has or what initialize does, but the > result of one of those functions from syslog is not an "engine" in the > sense of code that runs in a loop waiting for requests to do some work. > The result of those functions from syslog is a variable containing > state. When you invoke a method on one of those results, the method > runs in the current go routine, not the go routine where NewLogger, New, > or Dial was run. > > > Can we execute any linux command within goroutine to get some sort of > info > > on this ? >
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Marvin, Thanks for your response. "Do you mean "log/syslog" from the standard library? What does initialize do?" >>I have installed syslog-ng parser on my Linux box and I am planning you use syslog-ng parser and wanted to initialise it's engine for parsing the data. so initialise() method in my Go code calls C code that is wrapper around syslog-ng C header files.So ,I am making use of cgo *Following is my Go code:* func (obj Syslogparser) initialise{ X := C.CString(obj.X) defer C.free(unsafe.Pointer(X)) Y := C.CString(obj.Y) defer C.free(unsafe.Pointer(Y)) C.initialize_engine(X, Y, (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo))); } *And following is my C method 'initialize_engine':* int initialize_engine(const gchar* X, const gchar* Y, key_value_cb cb) // cb is callback function { // does some operation for initialising the engine of syslog-ng parser return 0; } 1)I want two instances of syslog-ng engine running on two different processors.How can I achieve this? 2)I made the following change : func main { var obj1 Syslogparser = initalize() // This initialises syslog-ng engine var obj2 Syslogparser// Not a package-level variable obj1.ParseMessage(program,msg)// this will parse the data and get the result if result["Z"] == "unknown"{ // On the basis of this result I want to initialise a new engine go func() { opts := Syslog{} obj2 = initalize() obj2.ReloadPatternDB(opts) obj2.ParseMessage(program, msg) }() } } Will this initialise two different syslog-ng engines for me ? 3)I understand goroutines are not OS threads and they just run on OS threads.Can we extract the process id of the running syslog-ng engines within the go routine where it spawned the syslog-ng engine ? Thanks On Wed, May 8, 2019 at 3:01 AM Marvin Renich wrote: > * Nitish Saboo [190507 14:07]: > > Thanks Michel for your detailed response. > > I am initialising the syslog engine. > > Do you mean "log/syslog" from the standard library? What does > initialize do? > > > var obj1 parser = initalize() > > var obj2 parser > > go func() { > > obj2 = initalize() > > }() > > You have initialized obj1, then you create a go routine that initializes > obj2. Assuming the initialization step takes a relatively short amount > of time and terminates, and does not itself create another go routine, > obj2 is not "on another go routine" (or thread or CPU or anything else). > It is simply another variable whose value was assigned by a different go > routine, but that go routine terminated immediately after obj2 was given > its value. > > Note that obj2 is a variable, not a running function; it is not > associated with a specific go routine, at least not in the sense that > you appear to be thinking. If obj2 is declared at the package level, > than any function in the package can reference it regardless of the go > routine in which that function is running. > > > if obj1 engine fails: > > go func() { > > obj2.ReloadPattern(opts) > > }() > > > > My question is, will obj2.ReloadPattern reload the pattern on the second > > syslog-engine , how can I verify that?Because I am not maintaining the > > engine info. I am just having the parser object. > > Will parser object obj2 go and reload the respective syslog engine that > was > > initialised by it? I guess yes, but still need clarification on this . > > A new go routine will be created (possibly unnecessarily, but you don't > give enough information), and the ReloadPattern method of obj2 will be > invoked in that go routine. When ReloadPattern terminates, the go > routine will also terminate. obj2 is still a package-level variable (or > associated with whatever scope in which it was declared). > > > Since I was not able to identify the exact syslog engine, I was trying to > > identify it using the processor. > > Since you don't give enough information, I'm going to take some guesses, > which could be completely wrong. I am guessing that you are using the > standard library "log/syslog" package, and you have encapsulated the > result of either NewLogger, New, or Dial from that package in your own > structure which is returned by initialize. Your structure has > additional fields and methods, and some of the methods call appropriate > methods on the value obtained from the syslog package. > > I don't know what your structure has or what initialize does, but the > result of one of those functions from syslog is not an "engine" in the > sense of code that runs in a loop waiting for requests to do some work. > The result of those functions from syslog is a variable containing > state. When you invoke a method on one of those results, the method > runs in the current go routine, not the go routine where NewLogger, New, > or Dial was run. > > > Can we execute any linux command within goroutine to get some sort of > info > > on this ? > > You seem to have some misconceptions about Go as a whole. In Java, > which is an object oriented language, you can
Re: [go-nuts] How to run a go method on multiple cores ?
* Nitish Saboo [190507 14:07]: > Thanks Michel for your detailed response. > I am initialising the syslog engine. Do you mean "log/syslog" from the standard library? What does initialize do? > var obj1 parser = initalize() > var obj2 parser > go func() { > obj2 = initalize() > }() You have initialized obj1, then you create a go routine that initializes obj2. Assuming the initialization step takes a relatively short amount of time and terminates, and does not itself create another go routine, obj2 is not "on another go routine" (or thread or CPU or anything else). It is simply another variable whose value was assigned by a different go routine, but that go routine terminated immediately after obj2 was given its value. Note that obj2 is a variable, not a running function; it is not associated with a specific go routine, at least not in the sense that you appear to be thinking. If obj2 is declared at the package level, than any function in the package can reference it regardless of the go routine in which that function is running. > if obj1 engine fails: > go func() { > obj2.ReloadPattern(opts) > }() > > My question is, will obj2.ReloadPattern reload the pattern on the second > syslog-engine , how can I verify that?Because I am not maintaining the > engine info. I am just having the parser object. > Will parser object obj2 go and reload the respective syslog engine that was > initialised by it? I guess yes, but still need clarification on this . A new go routine will be created (possibly unnecessarily, but you don't give enough information), and the ReloadPattern method of obj2 will be invoked in that go routine. When ReloadPattern terminates, the go routine will also terminate. obj2 is still a package-level variable (or associated with whatever scope in which it was declared). > Since I was not able to identify the exact syslog engine, I was trying to > identify it using the processor. Since you don't give enough information, I'm going to take some guesses, which could be completely wrong. I am guessing that you are using the standard library "log/syslog" package, and you have encapsulated the result of either NewLogger, New, or Dial from that package in your own structure which is returned by initialize. Your structure has additional fields and methods, and some of the methods call appropriate methods on the value obtained from the syslog package. I don't know what your structure has or what initialize does, but the result of one of those functions from syslog is not an "engine" in the sense of code that runs in a loop waiting for requests to do some work. The result of those functions from syslog is a variable containing state. When you invoke a method on one of those results, the method runs in the current go routine, not the go routine where NewLogger, New, or Dial was run. > Can we execute any linux command within goroutine to get some sort of info > on this ? You seem to have some misconceptions about Go as a whole. In Java, which is an object oriented language, you can create a Thread object, which lets you manipulate a new OS thread from within another, already existing, thread. First, Go is not an object oriented language, though you can (and it is often convenient to) use object oriented paradigms, just like you can use object oriented paradigms from C. Second, go routines are not OS threads. Different go routines are not guaranteed to run on different OS threads, though the Go scheduler is allowed to use multiple OS threads to run multiple go routines at the same time. Also, a specific go routine is not guaranteed to remain on a specific OS thread, unless you use runtime.LockOSThread. However, I would not recommend that you do so until your understanding of go routines is much more solid that it appears to be; you are unlikely to obtain the results you expect. Third, Go does not natively provide any means to identify specific go routines. This was an intentional language design. Such identification is almost never necessary, and in other languages is a frequently abused feature. Two of the common means in Go for one go routine to provide information about its own state to another go routine are channels and sync.WaitGroup, but one go routine cannot "inspect" another without prior arrangement between the two. It is unclear what you are trying to accomplish by having two "syslog engines". I get the vague impression that you want something like "high reliability" so that at least one "engine" is always running and can restart the other if the other fails. However, there is no indication of what might cause one to fail while the rest of your Go program is still running. If you are connecting to multiple syslog providers on distinct hosts using syslog.Dial, and trying to recover from an outage on one of the remote hosts, you are very likely better off having one log variable (obj1 from above?) that manages multiple *syslog.Writer values, perhaps with
Re: [go-nuts] How to run a go method on multiple cores ?
Thanks Michel for your detailed response. I am initialising the syslog engine. var obj1 parser = initalize() var obj2 parser go func() { obj2 = initalize() }() if obj1 engine fails: go func() { obj2.ReloadPattern(opts) }() My question is, will obj2.ReloadPattern reload the pattern on the second syslog-engine , how can I verify that?Because I am not maintaining the engine info. I am just having the parser object. Will parser object obj2 go and reload the respective syslog engine that was initialised by it? I guess yes, but still need clarification on this . Since I was not able to identify the exact syslog engine, I was trying to identify it using the processor. Can we execute any linux command within goroutine to get some sort of info on this ? Thanks On Tue, May 7, 2019 at 5:07 PM Michel Levieux wrote: > If the only thing you want to achieve is: > > main: > run engineA > run engineB > > engineA: > do something > if engineB is down -> run engineB > > engineB: > do something > if engineA is down -> run engineA > > You don't really need the two processes to run on different cores, nor do > you need them to be constantly running in parallel. You can just run both > engines in separate goroutines and trust the scheduler for their > management. Think of a goroutine as an abstraction. The goroutine is NOT a > thread, it is NOT bound to a CPU physical core at runtime (meaning it can > execute on any core, even on multiple ones in a single execution), the only > thing a goroutine does is decoupling the execution of a portion of code > from the other goroutines. I don't think you need to go deeper into the way > goroutines work to do what you're trying to achieve :) > > > Le mar. 7 mai 2019 à 13:02, Nitish Saboo a > écrit : > >> Hi Jan, >> >> I need two separate parsing engines to be running and I feel that is >> possible when it is running parallel on two different cores. >> If operation on one of the parsing engine fails, I will reload the other >> parsing engine and do the operation.This is what I want to achieve. >> I thought goroutines will help me initialising two separate parsing >> engines. >> >> Thanks >> >> >> On Tue, May 7, 2019 at 3:09 PM Jan Mercl <0xj...@gmail.com> wrote: >> >>> On Tue, May 7, 2019 at 11:27 AM Nitish Saboo >>> wrote: >>> >>> > I want to initialise parsing engines on two different processors. >>> >>> Are goroutines meant where we read 'processors'? If not, than this >>> maybe is an XY problem[0] and please explain why you need distinct >>> CPUs to execute the code. >>> >>> [0]: https://en.wikipedia.org/wiki/XY_problem >>> >> -- 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/CALjMrq7WK1vxSFwKB4eOtNWDTjfemG27ykGZ1-SghDtOuUqR_A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
If the only thing you want to achieve is: main: run engineA run engineB engineA: do something if engineB is down -> run engineB engineB: do something if engineA is down -> run engineA You don't really need the two processes to run on different cores, nor do you need them to be constantly running in parallel. You can just run both engines in separate goroutines and trust the scheduler for their management. Think of a goroutine as an abstraction. The goroutine is NOT a thread, it is NOT bound to a CPU physical core at runtime (meaning it can execute on any core, even on multiple ones in a single execution), the only thing a goroutine does is decoupling the execution of a portion of code from the other goroutines. I don't think you need to go deeper into the way goroutines work to do what you're trying to achieve :) Le mar. 7 mai 2019 à 13:02, Nitish Saboo a écrit : > Hi Jan, > > I need two separate parsing engines to be running and I feel that is > possible when it is running parallel on two different cores. > If operation on one of the parsing engine fails, I will reload the other > parsing engine and do the operation.This is what I want to achieve. > I thought goroutines will help me initialising two separate parsing > engines. > > Thanks > > > On Tue, May 7, 2019 at 3:09 PM Jan Mercl <0xj...@gmail.com> wrote: > >> On Tue, May 7, 2019 at 11:27 AM Nitish Saboo >> wrote: >> >> > I want to initialise parsing engines on two different processors. >> >> Are goroutines meant where we read 'processors'? If not, than this >> maybe is an XY problem[0] and please explain why you need distinct >> CPUs to execute the code. >> >> [0]: https://en.wikipedia.org/wiki/XY_problem >> > -- 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/CANgi337UioNgx17HgnsOZ-%3DveffYbyKnHFZjG6QPVpKdHvGp%2Bg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Jan, I need two separate parsing engines to be running and I feel that is possible when it is running parallel on two different cores. If operation on one of the parsing engine fails, I will reload the other parsing engine and do the operation.This is what I want to achieve. I thought goroutines will help me initialising two separate parsing engines. Thanks On Tue, May 7, 2019 at 3:09 PM Jan Mercl <0xj...@gmail.com> wrote: > On Tue, May 7, 2019 at 11:27 AM Nitish Saboo > wrote: > > > I want to initialise parsing engines on two different processors. > > Are goroutines meant where we read 'processors'? If not, than this > maybe is an XY problem[0] and please explain why you need distinct > CPUs to execute the code. > > [0]: https://en.wikipedia.org/wiki/XY_problem > -- 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/CALjMrq4MTDA5Ubxx8YTbACU2wmPB90EUBtSDskFu8_88%2BMnZPQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
On Tue, May 7, 2019 at 11:27 AM Nitish Saboo wrote: > I want to initialise parsing engines on two different processors. Are goroutines meant where we read 'processors'? If not, than this maybe is an XY problem[0] and please explain why you need distinct CPUs to execute the code. [0]: https://en.wikipedia.org/wiki/XY_problem -- 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/CAA40n-Xsk-2eviitUBfkDd1mp_HbipW2kXC_YaZZMvHPT6AbNQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Michel, I want to initialise parsing engines on two different processors.This I am achieving in the following manner: var obj1 parser = initalize() var obj2 parser go func() { obj2 = initalize() }() Post this I want to reload the engine of obj2 parser, which I am trying to achieve using the following code but I am not sure on which processor it is actually happening ? Will it happen on the same processor where obj2 parser engine got initialised ? go func() { obj2.ReloadPattern(opts) }() Thanks On Tue, May 7, 2019 at 2:08 PM Michel Levieux wrote: > I don't know of any primitives that would return the current processor the > goroutine is currently running on. Maybe if you explain more precisely what > you are trying to do, we can find a better solution? > > @lgodio2 no, as Jan said, the go statement is not an expression, so you > can't assign with it, you need to do either: > > func main() { > var s1 TYPE > go func () { > s1 = f1() > } > s2 := f2() > } > > OR > > func main() { > var s1 TYPE > var s2 TYPE > > go func () { > s1 = f1() > }() > > go func() { > s2 = f2() > }() > } > > However in the second solution, if you execute that in the main goroutine > or if you need those two assignments to be done before doing something > else, you might want to use synchronisation primitives such as waitgroups. > > Le mar. 7 mai 2019 à 07:51, Nitish Saboo a > écrit : > >> Hi Michel, >> >> Yes, this is what I was looking for.Thankyou..:) >> >> Can we also find the processor on which this go routine is running? >> >> Thanks >> >> >> On Mon, 6 May 2019, 17:43 Michel Levieux, >> wrote: >> >>> Hello, >>> >>> Is: >>> >>> type Y struct { >>> >>> M string >>> N string >>> >>> } >>> >>> func initalize() Y{ >>> // I have a func that return an object ob type Y. >>> } >>> >>> var obj1 Y >>> go func() { >>> obj1 = initalize() >>> }() >>> >>> var obj2 Y >>> go func() { >>> obj2 = initalize() >>> }() >>> >>> What you are looking for? >>> >>> Le lun. 6 mai 2019 à 13:59, Jan Mercl <0xj...@gmail.com> a écrit : >>> On Mon, May 6, 2019 at 1:39 PM Nitish Saboo wrote: > type Y struct { > > M string > N string > > } > > func initalize() Y{ > // I have a func that return an object ob type Y. > } > var obj1 Y = go initalize() No need to write Y above, the type will be inferred. However, see https://golang.org/ref/spec#Go_statements The go statement is not an expression while the `var foo = expr` requires an expression. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CALjMrq6nQRCSJCY89nE3hP2YmhvpgS5pcts7fN_-cqhdizPj1A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
I don't know of any primitives that would return the current processor the goroutine is currently running on. Maybe if you explain more precisely what you are trying to do, we can find a better solution? @lgodio2 no, as Jan said, the go statement is not an expression, so you can't assign with it, you need to do either: func main() { var s1 TYPE go func () { s1 = f1() } s2 := f2() } OR func main() { var s1 TYPE var s2 TYPE go func () { s1 = f1() }() go func() { s2 = f2() }() } However in the second solution, if you execute that in the main goroutine or if you need those two assignments to be done before doing something else, you might want to use synchronisation primitives such as waitgroups. Le mar. 7 mai 2019 à 07:51, Nitish Saboo a écrit : > Hi Michel, > > Yes, this is what I was looking for.Thankyou..:) > > Can we also find the processor on which this go routine is running? > > Thanks > > > On Mon, 6 May 2019, 17:43 Michel Levieux, > wrote: > >> Hello, >> >> Is: >> >> type Y struct { >> >> M string >> N string >> >> } >> >> func initalize() Y{ >> // I have a func that return an object ob type Y. >> } >> >> var obj1 Y >> go func() { >> obj1 = initalize() >> }() >> >> var obj2 Y >> go func() { >> obj2 = initalize() >> }() >> >> What you are looking for? >> >> Le lun. 6 mai 2019 à 13:59, Jan Mercl <0xj...@gmail.com> a écrit : >> >>> On Mon, May 6, 2019 at 1:39 PM Nitish Saboo >>> wrote: >>> >>> > type Y struct { >>> > >>> > M string >>> > N string >>> > >>> > } >>> > >>> > func initalize() Y{ >>> > // I have a func that return an object ob type Y. >>> > } >>> > var obj1 Y = go initalize() >>> >>> No need to write Y above, the type will be inferred. However, see >>> https://golang.org/ref/spec#Go_statements The go statement is not an >>> expression while the `var foo = expr` requires an expression. >>> >>> -- >>> 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANgi334APwcch%2B26XG_6RSqLObarfuyzPVn2-%2BmZPYXwvajbdg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to run a go method on multiple cores ?
Hi Michel, Yes, this is what I was looking for.Thankyou..:) Can we also find the processor on which this go routine is running? Thanks On Mon, 6 May 2019, 17:43 Michel Levieux, wrote: > Hello, > > Is: > > type Y struct { > > M string > N string > > } > > func initalize() Y{ > // I have a func that return an object ob type Y. > } > > var obj1 Y > go func() { > obj1 = initalize() > }() > > var obj2 Y > go func() { > obj2 = initalize() > }() > > What you are looking for? > > Le lun. 6 mai 2019 à 13:59, Jan Mercl <0xj...@gmail.com> a écrit : > >> On Mon, May 6, 2019 at 1:39 PM Nitish Saboo >> wrote: >> >> > type Y struct { >> > >> > M string >> > N string >> > >> > } >> > >> > func initalize() Y{ >> > // I have a func that return an object ob type Y. >> > } >> > var obj1 Y = go initalize() >> >> No need to write Y above, the type will be inferred. However, see >> https://golang.org/ref/spec#Go_statements The go statement is not an >> expression while the `var foo = expr` requires an expression. >> >> -- >> 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.
Re: [go-nuts] How to run a go method on multiple cores ?
Hello, Is: type Y struct { M string N string } func initalize() Y{ // I have a func that return an object ob type Y. } var obj1 Y go func() { obj1 = initalize() }() var obj2 Y go func() { obj2 = initalize() }() What you are looking for? Le lun. 6 mai 2019 à 13:59, Jan Mercl <0xj...@gmail.com> a écrit : > On Mon, May 6, 2019 at 1:39 PM Nitish Saboo > wrote: > > > type Y struct { > > > > M string > > N string > > > > } > > > > func initalize() Y{ > > // I have a func that return an object ob type Y. > > } > > var obj1 Y = go initalize() > > No need to write Y above, the type will be inferred. However, see > https://golang.org/ref/spec#Go_statements The go statement is not an > expression while the `var foo = expr` requires an expression. > > -- > 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.
Re: [go-nuts] How to run a go method on multiple cores ?
On Mon, May 6, 2019 at 1:39 PM Nitish Saboo wrote: > type Y struct { > > M string > N string > > } > > func initalize() Y{ > // I have a func that return an object ob type Y. > } > var obj1 Y = go initalize() No need to write Y above, the type will be inferred. However, see https://golang.org/ref/spec#Go_statements The go statement is not an expression while the `var foo = expr` requires an expression. -- 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.
Re: [go-nuts] How to run a go method on multiple cores ?
Thanks Jan. type Y struct { M string N string } func initalize() Y{ // I have a func that return an object ob type Y. } var obj1 Y = go initalize() var obj2 Y = go initalize() Let me know how to call a go routine in this case, because when I am doing it in this way I am getting compilation error. Thanks. On Mon, May 6, 2019 at 4:55 PM Jan Mercl <0xj...@gmail.com> wrote: > On Mon, May 6, 2019 at 1:11 PM Nitish Saboo > wrote: > > > > Hi, > > > > I want a go method to run on multiple cores.The go method is returning > an object. Can we achieve this using goroutine ? > > How can I achieve this ? > > In the first approximation, to run a a function/method f() in a > goroutine on N cores/threads, provided N is equal GOMAXPROCS, execute > `go f()` N times. > > Why do you care about "stick to core"? If the goroutines have work to > do, they will get spread by the scheduler between threads/cores > anyway. > -- 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.
Re: [go-nuts] How to run a go method on multiple cores ?
On Mon, May 6, 2019 at 1:11 PM Nitish Saboo wrote: > > Hi, > > I want a go method to run on multiple cores.The go method is returning an > object. Can we achieve this using goroutine ? > How can I achieve this ? In the first approximation, to run a a function/method f() in a goroutine on N cores/threads, provided N is equal GOMAXPROCS, execute `go f()` N times. Why do you care about "stick to core"? If the goroutines have work to do, they will get spread by the scheduler between threads/cores anyway. -- 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.
[go-nuts] How to run a go method on multiple cores ?
Hi, I want a go method to run on multiple cores.The go method is returning an object. Can we achieve this using goroutine ? How can I achieve this ? Thanks -- 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.