'\" te .\" Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. .TH smt_pause 3C "3 Dec 2015" "SunOS 5.11" "Standard C Library Functions" .SH NAME smt_pause, smt_nano_pause \- busy wait idle function .SH SYNOPSIS .LP .nf #include void smt_pause(void); void smt_nano_pause(hrtime_t nsec); .fi .SH DESCRIPTION .sp .LP The \fBsmt_pause()\fR and \fBsmt_nano_pause()\fR functions are recommended for use in busy wait loops to lessen the impact the loop has on the rest of the system. For example, on CMT systems they enable other hardware strands sharing the core to go faster during the busy wait. .sp .LP The \fBsmt_pause()\fR function delays for a short implementation-dependent period before returning to the caller, consuming as few processor resources as possible. .sp .LP The \fBsmt_nano_pause()\fR function also delays while conserving processor resources but takes the \fBnsec\fR argument to specify the elapsed time of the pause in nanoseconds. The elapsed time will be at least the number of nanoseconds specified and may be greater. The calling thread remains scheduled on the current CPU from an operating system point of view. If the pause duration is expected to be longer than the minimum duration of calls that block such as \fBnanosleep\fR(3C) or \fBpoll\fR(2), then overall thread utilization may be improved by using those calls instead. .sp .LP The \fBsmt_nano_pause()\fR function has no effect on the action or blockage of any signal, and will continue pausing after returning from a signal handler. .SH USAGE .sp .LP The usage of \fBsmt_pause()\fR function is as follows: .sp .in +2 .nf volatile int *wait; while (*wait == 1) smt_pause(); .fi .in -2 .sp .LP The \fBsmt_nano_pause()\fR function might be used in an exponential backoff algorithm: .sp .in +2 .nf volatile int *wait; hrtime_t backoff = 20; while (*wait == 1) { if (backoff > 10000000) /* 0.01 seconds */ poll(0, 0, backoff / 1000000); else smt_nano_pause(backoff); backoff *= 2; } .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe .TE .SH SEE ALSO .sp .LP \fBattributes\fR(5), \fBnanosleep\fR(3C), \fBsleep\fR(3C)