DispatchSource (a.k.a. dispatch_source_t) vs kevent

Short one:


on macOS - is DispatchSource built on top of kevent? I suspect yes, but I can not find a direct mention.


thx!

Accepted Reply

As an implementation detail, yes, it does. To verify, consider the output of this command:


nm -m /usr/lib/system/libdispatch.dylib | egrep -e '(\b|_)kqueue' -e '(\b|_)kevent'

Replies

As an implementation detail, yes, it does. To verify, consider the output of this command:


nm -m /usr/lib/system/libdispatch.dylib | egrep -e '(\b|_)kqueue' -e '(\b|_)kevent'

is DispatchSource built on top of kevent?

Just out of curiosity, why does this matter to you?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

a) just curious as you 😉

b) if you search apple docs how to handle file system changes - it directs you to kevents not to GCD (legacy stuff)

c) documentation on DispatchSource does not explain event semantics too well, while `man kevent` does. wanted to know they are semantically equal.

b) if you search apple docs how to handle file system changes - it directs you to kevents not to GCD (legacy stuff)

Quite. That’s just because kevents were introduced before Dispatch.

I’d appreciate you filing bugs against docs like this. There are some good reasons to use kevents, like compatibility with other platforms, but the bulk of our developers should use dispatch sources for this sort of thing. Using kevents correctly is really hard.

c) documentation on

DispatchSource
does not explain event semantics too well, while
man kevent
does. wanted to know they are semantically equal.

Again, if you find the Dispatch documentation inadequate that’s totally bugworthy.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Question: If DispatchSource built on top of kevent, how come it won't blocking thread? it seems it runs different routine of pthread mechanism to create a thread to execute(if handler is executed on different thread) instead of blocking current thread.