To a first order approximation, there is no guarantee of events between any 
two go processes. The scheduler is free to chose any unblocked process. 
Here's what I think is happening.

go sync () // creates the sync routine
fmt.Println("0") // prints
time.Sleep(time.Second) // sends this routine to sleep
// scheduler looks for work
fmt.Println("1")
time.Sleep(time.Second) // sends the other routine to sleep
// scheduler now has 2 routines waiting for a second to elapse
// sufficient timer ticks elapse for a second to be counted as passing
// both routines "unsleep" and are marked as being able to be scheduled
// scheduler looks for something to do
// may pick either routine, probably sensible though to go back to the last 
routine that did work
// (cache locality and all that)
fmt.Println("3")
time.Sleep(time.Second)
// scheduler looks for work
fmt.Println("2")

Again once you have work in the queue, the scheduler is free to schedule 
work from that queue in any order. The timer tick will probably (but not 
certainly) mean that both these routines unblock concurrently and so are on 
the work queue at the same moment.
Unless I am much mistaken the scheduler is architecturally free to swap 
between active routines at any time. I believe the current design will 
normally only evaluate the swap (cooperatively multi-task) on function 
calls (I could be mis-remembering this though).

HTH

Chris


On Monday, 8 April 2019 14:38:40 UTC+1, go je 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 <laure...@gmail.com <javascript:>> 
> 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 golan...@googlegroups.com <javascript:>.
>> 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.

Reply via email to