xref: /netbsd-src/lib/libpthread/pthread_suspend_np.3 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\" $NetBSD: pthread_suspend_np.3,v 1.5 2010/07/09 09:18:45 jruoho Exp $
2.\"
3.\" Copyright (c) 2003, 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd July 9, 2010
31.Dt PTHREAD_SUSPEND_NP 3
32.Os
33.Sh NAME
34.Nm pthread_suspend_np ,
35.Nm pthread_resume_np
36.Nd suspend/resume the given thread
37.Sh LIBRARY
38.Lb libpthread
39.Sh SYNOPSIS
40.In pthread.h
41.Ft int
42.Fn pthread_suspend_np "pthread_t thread"
43.Ft int
44.Fn pthread_resume_np "pthread_t thread"
45.Sh DESCRIPTION
46The
47.Fn pthread_suspend_np
48function suspends the
49.Fa thread
50given as argument.
51If
52.Fa thread
53is the currently running thread as returned by
54.Xr pthread_self 3 ,
55the function fails and returns
56.Er EDEADLK .
57Otherwise, it removes the named thread from the running queue, and
58adds it to the suspended queue.
59The
60.Fa thread
61will remain blocked until
62.Fn pthread_resume_np
63is called on it.
64In other words,
65.Fn pthread_resume_np
66resumes the
67.Fa thread
68given as argument, if it was suspended.
69.Sh RETURN VALUES
70Both functions return 0 on success and an error number indicating the
71reason for the failure.
72.Sh COMPATIBILITY
73These functions are non-standard extensions.
74.Sh ERRORS
75The
76.Fn pthread_suspend_np
77function may fail if:
78.Bl -tag -width Er
79.It Bq Er EDEADLK
80The thread requested to suspend was the currently running thread.
81.It Bq Er ESRCH
82The supplied
83.Fa thread
84was invalid.
85.El
86.Pp
87The
88.Fn pthread_resume_np
89function may fail if:
90.Bl -tag -width Er
91.It Bq Er ESRCH
92The supplied
93.Fa thread
94was invalid.
95.El
96.Sh NOTES
97Some
98.Fn pthread_suspend_np
99implementations may allow suspending the current thread.
100This is dangerous, because the semantics of the function would then
101require the scheduler to schedule another thread, causing a thread
102context switch.
103Since that context switch can happen in a signal handler by someone
104calling
105.Fn pthread_suspend_np
106in a signal handler, this is currently not allowed.
107.Pp
108In
109.Fn pthread_resume_np
110the
111.Nx
112implementation does not check if the
113.Fa thread
114argument is not already suspended.
115Some implementations might return an error condition if
116.Fn pthread_resume_np
117is called on a non-suspended thread.
118.Sh SEE ALSO
119.Xr pthread_attr_setcreatesuspend_np 3 ,
120.Xr pthread_self 3
121