I added this at the top of your main "fmt.Println("CPU Count",
runtime.NumCPU())", and found out that the playground uses 1 CPU, so your
goroutines will not run concurrently.

The scheduler will do a context switch whenever you call a any number of
runtime functions, but it is fundamentally cooperative multitasking, not
pre-emptive. So, you can produce deterministic output in your example, but
you are just getting lucky when that happens. There is no guarantee about
the wake latency of sleep, for example, and there is no guarantee in a
concurrent system about the order of your printouts, since all you know is
that you have two execution contexts, but know nothing about how they'll be
scheduled.

If you want ordered output in such a program, you have to use
synchronization primitives from the sync package.

On Mon, Apr 8, 2019 at 6:38 AM go je <laurengoc...@gmail.com> wrote:

> ascending only work if i cut the first sleep half second to print them
> alternately but isn't they sequentially running?
>
> On Mon, Apr 8, 2019 at 9:30 PM go je <laurengoc...@gmail.com> wrote:
>
>> https://play.golang.org/p/0TIxVFuqGoB
>>
>> --
>> 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.
>>
>
>
> --
>
>
>
>
>
> lol
>
> --
> 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.

Reply via email to