Parker(事件等待)

WaitOnAdress
https://github.com/mldbai/mldb/blob/master/arch/wait_on_address.cc
https://github.com/pitdicker/valet_parking/blob/master/src/futex/darwin.rs
Cross-platform atomic wait and wake (aka futex) functionality for Rust.
https://github.com/m-ou-se/atomic-wait

os_unfair_lock_lock -> _os_unfair_lock_lock_slow -> __ulock_wait
https://www.jianshu.com/p/2d3e73f8357f

1
2
3
#include <sys/syscall.h>
#define SYS_ulock_wait 515
#define SYS_ulock_wake 516

_dispatch_wait_on_address
https://github.com/tanghaitao/OC-learn-master/blob/master/chapter8/libdispatch-685/src/shims/lock.c#L180

1
2
std::atomic_bool wait = false;
while(1) std::atomic_wait(&wait, false);

__std_atomic_wait_direct (WaitOnAddress)
https://github.com/microsoft/STL/blob/main/stl/src/atomic_wait.cpp
__libcpp_platform_wait_on_address (__ulock_wait/futex)
https://github.com/llvm/llvm-project/blob/main/libcxx/src/atomic.cpp
__platform_wait (futex)
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/atomic_wait.h

Wait 函数
https://docs.microsoft.com/zh-cn/windows/win32/sync/wait-functions

原子内存顺序

https://github.com/microsoft/STL/blob/main/stl/inc/atomic
arm内存屏障 __dmb(0xB) x86/x64编译器屏障_ReadWriteBarrier(也算内存屏障吧)
https://github.com/llvm/llvm-project/blob/main/libcxx/include/atomic
__c11_atomic_thread_fence(llvm builtin) __atomic_thread_fence(llvm builtin)
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/atomic_base.h
__atomic_thread_fence(gcc builtin)

理解 C++ 的 Memory Order
http://senlinzhan.github.io/2017/12/04/cpp-memory-order/

内存模型与c++中的memory order
https://www.cnblogs.com/ishen/p/13200838.html

C++11多线程内存序(std::memory_order_seq_cst )
https://blog.csdn.net/qls315/article/details/105273506

Timer(定时器)

https://blog.csdn.net/dengjingen/article/details/121443040

1
2
while(1) select(0,0,0,0,&timeval);
// while(1) select(0,0,0,0,0);

https://docs.microsoft.com/zh-cn/windows/win32/sync/using-waitable-timer-objects
CreateWaitableTimer/CreateThreadpoolTimer(win32)
https://wirelessr.gitbooks.io/working-life/content/linux_timer.html
timer_create/timerfd_create(linux)
https://www.jianshu.com/p/b9d9fea2b56b
https://github.com/CoreNGS/tests/blob/main/sys/kqueue/libkqueue/timer.c
dispatch_source/EVFILT_TIMER+EV_ONESHOT(xnu)

Clock(计时器)

Monotonic Clock (steady_clock)
https://github.com/llvm/llvm-project/blob/main/libcxx/src/chrono.cpp
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B11/chrono.cc
https://github.com/microsoft/STL/blob/main/stl/src/xtime.cpp

Waker(事件消息/IO唤醒)

eventfd(linux) iocp[afd]/msg(win32) EVFILT_USER/mach_msg(xnu)
user space + cross process(?) : eventfd/iocp[afd]/EVFILT_USER+NOTE_TRIGGER(?)
all : pipe socket or unix domain socket
https://github.com/tokio-rs/mio/blob/master/src/waker.rs

1
2
3
/// On platforms that support kqueue this will use the `EVFILT_USER` event
/// filter, see [implementation notes of `Poll`] to see what platforms support
/// kqueue. On Linux it uses [eventfd].

https://github.com/boostorg/asio/blob/develop/include/boost/asio/detail/select_interrupter.hpp
https://github.com/libuv/libuv/blob/master/src/unix/async.c
https://github.com/libuv/libuv/blob/master/src/win/async.c
https://github.com/qt/qtbase/blob/dev/src/corelib/kernel/qeventdispatcher_unix.cpp
[epoll_post_signal]
https://github.com/an-tao/trantor/tree/master/third_party/wepoll
https://github.com/rbrich/xcikit/tree/master/src/xci/core/event
https://github.com/mheily/libkqueue

Shared Memory(共享内存)

shmget(sysv)/shm_open+mmap(posix)/OpenFileMapping(win32)
MMAP和read的区别
https://blog.csdn.net/wuguinianjing/article/details/111049193

INSECTION: AWESOMELY EXPLOITING SHARED MEMORY OBJECTS
http://publications.alex-ionescu.com/Infiltrate/Infiltrate%202015%20-%20Insection%20-%20Awesomly%20Exploiting%20Shared%20Memory%20Objects.pdf