macOS CFRunLoop Internals: Scheduling High-Precision Timers and Recurring Tasks

2 comments · 94% upvoted · source · other discussions

comments

ra3don [OP]

This is the first in a series of posts I have planned about working with low-level run loop APIs provided by the CoreFoundation C library. I demonstrate how they can be used in a C++ app by building up some higher level abstractions and RAII wrappers.

The next post I have planned goes over how we can use the CFRunLoop to post cross-thread tasks, and will include some benchmarks comparing with an alternative C++ lock-free SPSC task queue implementation.

hak8or

For those wondering what the heck a cfrunloop is;

https://developer.apple.com/documentation/corefoundation/cfrunloop-rht

A CFRunLoop object monitors sources of input to a task and dispatches control when they become ready for processing. Examples of input sources might include user input devices, network connections, periodic or time-delayed events, and asynchronous callbacks.