1# zx_nanosleep
2
3## NAME
4
5<!-- Updated by update-docs-from-abigen, do not edit. -->
6
7nanosleep - high resolution sleep
8
9## SYNOPSIS
10
11<!-- Updated by update-docs-from-abigen, do not edit. -->
12
13```
14#include <zircon/syscalls.h>
15
16zx_status_t zx_nanosleep(zx_time_t deadline);
17```
18
19## DESCRIPTION
20
21`zx_nanosleep()` suspends the calling thread execution until *deadline* passes on
22**ZX_CLOCK_MONOTONIC**. A *deadline* value less than or equal to **0**
23immediately yields the thread.
24
25To sleep for a duration, use [`zx_deadline_after()`] and the
26**ZX_\<time-unit\>** helpers:
27
28```
29#include <zircon/syscalls.h> // zx_deadline_after, zx_nanosleep
30#include <zircon/types.h> // ZX_MSEC et al.
31
32// Sleep 50 milliseconds
33zx_nanosleep(zx_deadline_after(ZX_MSEC(50)));
34```
35
36The nanosleep duration has 10% late slack with a minimum slack time of 1
37microsecond and a maximum slack time of 1 second. This slack time is the amount
38of additional time that the thread might sleep before being rescheduled. For
39example, a thread that requests a nanosleep with a duration of 1 second will
40have a slack time of .1 second. This means that the thread will sleep anywhere
41between 1 and 1.1 seconds. See [`zx_timer_set()`] for a more in-depth
42description of slack.
43
44The slack is included so the operating system can coalesce sleeps for
45performance and energy reasons.  If more precise timing is needed, it is
46recommended to use a timer.
47
48## RIGHTS
49
50<!-- Updated by update-docs-from-abigen, do not edit. -->
51
52None.
53
54## RETURN VALUE
55
56`zx_nanosleep()` always returns **ZX_OK**.
57
58## SEE ALSO
59
60 - [`zx_deadline_after()`]
61 - [`zx_timer_cancel()`]
62 - [`zx_timer_create()`]
63 - [`zx_timer_set()`]
64
65<!-- References updated by update-docs-from-abigen, do not edit. -->
66
67[`zx_deadline_after()`]: deadline_after.md
68[`zx_timer_cancel()`]: timer_cancel.md
69[`zx_timer_create()`]: timer_create.md
70[`zx_timer_set()`]: timer_set.md
71