FAQ
Hi all,

I am now using multi-goroutines in my program. As far as I know, when I use
the command "go somefunc()" in my code, it will create a new goroutine, but
Go does not guarantee when the new goroutine will start to execute. Is
there any way that I can let the new goroutine start to execute immediately?

Thanks,
Robert

--

Search Discussions

  • Evan Shaw at Nov 2, 2012 at 1:46 am

    On Fri, Nov 2, 2012 at 2:34 PM, Robert Sandra wrote:
    I am now using multi-goroutines in my program. As far as I know, when I use
    the command "go somefunc()" in my code, it will create a new goroutine, but
    Go does not guarantee when the new goroutine will start to execute. Is there
    any way that I can let the new goroutine start to execute immediately?
    If you want something to execute immediately, why start a new
    goroutine? Just make a synchronous call.

    - Evan

    --
  • Larry Clapp at Nov 2, 2012 at 2:06 am

    On Thursday, November 1, 2012 9:34:07 PM UTC-4, Robert Sandra wrote:

    I am now using multi-goroutines in my program. As far as I know, when I
    use the command "go somefunc()" in my code, it will create a new goroutine,
    but Go does not guarantee when the new goroutine will start to execute. Is
    there any way that I can let the new goroutine start to execute immediately?
    What have you run into that leads you believe that this is a problem?

    -- Larry


    --
  • Maxim Khitrov at Nov 2, 2012 at 2:10 am

    On Thu, Nov 1, 2012 at 9:34 PM, Robert Sandra wrote:
    Hi all,

    I am now using multi-goroutines in my program. As far as I know, when I use
    the command "go somefunc()" in my code, it will create a new goroutine, but
    Go does not guarantee when the new goroutine will start to execute. Is there
    any way that I can let the new goroutine start to execute immediately?

    Thanks,
    Robert
    Here are three options that I can think of:

    http://play.golang.org/p/-Zg0fg4VEl

    I don't think that option A is guaranteed to begin executing your
    goroutine. It does in the example because there is nothing else to do,
    but in another application there could be some other goroutine waiting
    to run.

    Option B may do what you want, but I believe that it could also switch
    back to the parent goroutine at the close(ch) call. As a result, it
    wouldn't really accomplish anything useful.

    Option C seems reasonable, but there could be some nuances with
    sync.Mutex that I'm not aware of.

    What is the actual problem you are trying to solve? In general, it
    shouldn't matter when the new goroutine begins executing. It will run
    as needed to satisfy channel operations. Beyond that, it's hard to
    predict or control. I think the plan is to introduce preemption into
    the scheduler at some point, which will also alter goroutine
    execution.

    - Max

    --
  • Jesse McNelis at Nov 2, 2012 at 4:57 am

    On Fri, Nov 2, 2012 at 12:34 PM, Robert Sandra wrote:

    I am now using multi-goroutines in my program. As far as I know, when I
    use the command "go somefunc()" in my code, it will create a new goroutine,
    but Go does not guarantee when the new goroutine will start to execute. Is
    there any way that I can let the new goroutine start to execute immediately?
    The definition of 'immediately' in a concurrent system is vague. If you
    think you have a
    need for something to happen 'immediately' then you've probably got a race
    condition somewhere in your design.


    --
    =====================
    http://jessta.id.au

    --
  • Si guy at Nov 2, 2012 at 6:11 am
    I would say that the definition of immediately in a Von Neumann type computer is vague.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 2, '12 at 1:34a
activeNov 2, '12 at 6:11a
posts6
users6
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase