---
name: "SDL_AddTimerNS"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_AddTimerNS"
---

# SDL\_AddTimerNS(3)

Call a callback function at a future time.

## NAME

SDL\_AddTimerNS - Call a callback function at a future time.

## HEADER FILE

Defined in SDL3/SDL\_timer.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**SDL\_TimerID SDL\_AddTimerNS(Uint64 interval, SDL\_NSTimerCallback callback, void \*userdata);**

## DESCRIPTION

The callback function is passed the current timer interval and the user supplied parameter from the  **SDL\_AddTimerNS** () call and should return the next timer interval. If the value returned from the callback is 0, the timer is canceled and will be removed.

The callback is run on a separate thread, and for short timeouts can potentially be called before this function returns.

Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ns to execute and returned 1000 (ns), the timer would only wait another 750 ns before its next iteration.

Timing may be inexact due to OS scheduling. Be sure to note the current time with  **SDL\_GetTicksNS** () or

**SDL\_GetPerformanceCounter** () in case your callback needs to adjust for variances.

## FUNCTION PARAMETERS

- *interval*

  the timer delay, in nanoseconds, passed to **callback** .

- *callback*

  the  **SDL\_TimerCallback**\
    function to call when the specified **interval** elapses.

- *userdata*

  a pointer that is passed to **callback** .

## RETURN VALUE

( **SDL\_TimerID** ) Returns a timer ID or 0 on failure; call

**SDL\_GetError** () for more information.

## THREAD SAFETY

It is safe to call this function from any thread.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_AddTimer**(3)](/SDL_AddTimer/3.md), **•**(3), [**SDL\_RemoveTimer**(3)](/SDL_RemoveTimer/3.md)
