一些关于noteXX函数的疑问
来源:1-4 Go 程序是怎么跑起来的
tan_beta
2021-06-23 23:01:08
3回答
Xargin
2021-07-01
notewakeup底层的semawakeup是通过信号量semaphore来唤醒m的么?
这个 semawakeup 在 linux 上是没有的。。

同时研究多个平台太累了,还是针对 linux 来看比较好~
Xargin
2021-07-01
以notewakeup为例,是怎么通过参数note中的key找到m的,继而唤醒他的?是指针偏移找的么?
这个是 futex 提供的功能吧。。这个关联关系要去 linux 内核找了~
Xargin
2021-07-01
1.
我看了看,这个 note 这套是 runtime 里比较底层的通知唤醒机制
// sleep and wakeup on one-time events.
// before any calls to notesleep or notewakeup,
// must call noteclear to initialize the Note.
// then, exactly one thread can call notesleep
// and exactly one thread can call notewakeup (once).
// once notewakeup has been called, the notesleep
// will return. future notesleep will return immediately.
// subsequent noteclear must be called only after
// previous notesleep has returned, e.g. it's disallowed
// to call noteclear straight after notewakeup.
//
// notetsleep is like notesleep but wakes up after
// a given number of nanoseconds even if the event
// has not yet happened. if a goroutine uses notetsleep to
// wake up early, it must wait to call noteclear until it
// can be sure that no other goroutine is calling
// notewakeup.
这套机制在 linux 是通过 futex 实现的,这个是 linux 提供的一个编程工具。
相似问题