Skip to content

Precision of `threadDelay` with -threaded could be increased on Linux

Motivation

threadDelay takes a sleep duration as a number of microseconds, but the implementation used on Linux when -theaded is specified uses much coarser precision, leading to surprise.

Current implementation

When using the epoll backend, the timer manager uses the timeout argument to epoll_wait to service threadDelay requests. However, this has only millisecond precision, and it's also round up to the system clock granularity.

Proposed change

The epoll backend maintains a timer fd (created using timerfd_create), and uses it whenever a finite timeout is requested.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information