That's a really useful workaround! It makes much more sense now.

Conclusion: when `sigtramp` is returned, nothing is called before entering 
`ayncPreempt`.

Thank you so much for releasing me from confusing :)

sigtramp is returned
asyncPreempt is called
OK


 CALL runtime·sigtrampgo(SB)
 CALL runtime·printmsg(SB)


TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
 CALL runtime·printmsg2(SB)


var msg1 = []byte("sigtramp is returned\n")
var msg2 = []byte("asyncPreempt is called\n")


//go:nosplit
func printmsg() {
 write(2, unsafe.Pointer(&msg1[0]), int32(len(msg1)))
}


//go:nosplit
func printmsg2() {
 write(2, unsafe.Pointer(&msg2[0]), int32(len(msg2)))
}




On Monday, December 9, 2019 at 12:42:42 AM UTC+1, Ian Lance Taylor wrote:
>
> On Sun, Dec 8, 2019 at 1:10 PM changkun <euryu...@gmail.com <javascript:>> 
> wrote: 
> > 
> > Thank you so much for your hint, I think I've figured it out. 
> > The root cause seems similar to the "uncertainty principle". 
> > 
> > As an observer, by adding a `println` call in `asyncPreempt` 
> > as well as `asyncPreempt2` influences the actual behavior 
> > after signal handling. The `println` involves stack split check, 
> > which calls the `morestack`. 
>
> Ah, of course.  One workaround is to use write, as in 
>
> // Package-scope variable 
> var myMsg = []byte("my message") 
>
> // In function. 
>     write(2, unsafe.Pointer(&myMsg[0]), int32(len(myMsg))) 
>
> This works because the various implementations of write are marked 
> nosplit. 
>
> Ian 
>

-- 
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/a5f72949-0b52-48cb-b477-73f0fc4151ee%40googlegroups.com.

Reply via email to