1schedctl_init(3C) Standard C Library Functions schedctl_init(3C)
2
3
4
6 schedctl_init, schedctl_lookup, schedctl_exit, schedctl_start, sched‐
7 ctl_stop - preemption control
8
10 cc [ flag... ] file... [ library... ]
11 #include <schedctl.h>
12
13 schedctl_t *schedctl_init(void);
14
15
16 schedctl_t *schedctl_lookup(void);
17
18
19 void schedctl_exit(void);
20
21
22 void schedctl_start(schedctl_t *ptr);
23
24
25 void schedctl_stop(schedctl_t *ptr);
26
27
29 These functions provide limited control over the scheduling of a thread
30 (see threads(5)). They allow a running thread to give a hint to the
31 kernel that preemptions of that thread should be avoided. The most
32 likely use for these functions is to block preemption while holding a
33 spinlock. Improper use of this facility, including attempts to block
34 preemption for sustained periods of time, may result in reduced perfor‐
35 mance.
36
37
38 The schedctl_init() function initializes preemption control for the
39 calling thread and returns a pointer used to refer to the data. If
40 schedctl_init() is called more than once by the same thread, the most
41 recently returned pointer is the only valid one.
42
43
44 The schedctl_lookup() function returns the currently allocated preemp‐
45 tion control data associated with the calling thread that was previ‐
46 ously returned by schedctl_init(). This can be useful in programs where
47 it is difficult to maintain local state for each thread.
48
49
50 The schedctl_exit() function removes the preemption control data asso‐
51 ciated with the calling thread.
52
53
54 The schedctl_start() macro gives a hint to the kernel scheduler that
55 preemption should be avoided on the current thread. The pointer passed
56 to the macro must be the same as the pointer returned by the call to
57 schedctl_init() by the current thread. The behavior of the program when
58 other values are passed is undefined.
59
60
61 The schedctl_stop() macro removes the hint that was set by sched‐
62 ctl_start(). As with schedctl_start(), the pointer passed to the macro
63 must be the same as the pointer returned by the call to schedctl_init()
64 by the current thread.
65
66
67 The schedctl_start() and schedctl_stop() macros are intended to be used
68 to bracket short critical sections, such as the time spent holding a
69 spinlock. Other uses, including the failure to call schedctl_stop()
70 soon after calling schedctl_start(), might result in poor performance.
71
73 The schedctl_init() function returns a pointer to a schedctl_t struc‐
74 ture if the initialization was successful, or NULL otherwise. The
75 schedctl_lookup() function returns a pointer to a schedctl_t structure
76 if the data for that thread was found, or NULL otherwise.
77
79 No errors are returned.
80
82 See attributes(5) for descriptions of the following attributes:
83
84
85
86
87 ┌─────────────────────────────┬─────────────────────────────┐
88 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
89 ├─────────────────────────────┼─────────────────────────────┤
90 │Interface Stability │Stable │
91 ├─────────────────────────────┼─────────────────────────────┤
92 │MT-Level │MT-Safe │
93 └─────────────────────────────┴─────────────────────────────┘
94
96 priocntl(1), exec(2), fork(2), priocntl(2), attributes(5), threads(5)
97
99 Preemption control is intended for use by threads belonging to the
100 time-sharing (TS), interactive (IA), fair-share (FSS), and fixed-prior‐
101 ity (FX) scheduling classes. If used by threads in other scheduling
102 classes, such as real-time (RT), no errors will be returned but sched‐
103 ctl_start() and schedctl_stop() will not have any effect.
104
105
106 The data used for preemption control are not copied in the child of a
107 fork(2). Thus, if a process containing threads using preemption control
108 calls fork and the child does not immediately call exec(2), each thread
109 in the child must call schedctl_init() again prior to any future uses
110 of schedctl_start() and schedctl_stop(). Failure to do so will result
111 in undefined behavior.
112
113
114
115SunOS 5.11 28 May 2003 schedctl_init(3C)