HaxeFoundation / HaxeFoundation/hxcpp

Replace usage of `gettimeofday` in the hxcpp standard library

Open
#887 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

On non-windows platforms `gettimeofday()` (time.h) is used in the hxcpp stdlib to get a timestamp for time-deltas, however, gettimeofday has several issues when used for this purpose:
- It's linked to the user's OS clock, so it changes if the user's clock changes, this is a big problem for long-running applications (physical installations and whatnot) where the system clock is likely to change while the app is open
- It's not monotonically increasing so you might get negative time deltas
- Since it's used in hxcpp threading primitives, if the user changes their system clock their app may hang (for example a lock timeout might be left waiting for hours rather than an intended few ms)

Some uses in the standard library include:
- Time delta when when waiting on locks
- Time delta in event scheduling
- haxe.Timer.stamp()

See the following article for more details: [gettimeofday should never be used to measure time](https://blog.habets.se/2010/09/gettimeofday-should-never-be-used-to-measure-time.html)

On linux we should use `clock_gettime(CLOCK_MONOTONIC, ...)` and to support old mac os systems we should use `mach_absolute_time()`

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect the hxcpp standard-library call sites that use gettimeofday for lock waits, event scheduling, and haxe.Timer.stamp(). Compare the Linux clock_gettime(CLOCK_MONOTONIC) and older macOS mach_absolute_time() options described in the issue. Done means these time-delta uses no longer depend on the adjustable OS clock and cannot produce negative deltas or extended timeout waits after a clock change.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.