1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-1998. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Thread Manager |
---|
10 | |
---|
11 | @section Introduction |
---|
12 | |
---|
13 | The thread manager implements the functionality required of the thread |
---|
14 | manager as defined by POSIX 1003.1b-1996. This standard requires that |
---|
15 | a compliant operating system provide the facilties to manage multiple |
---|
16 | threads of control and defines the API that must be provided. |
---|
17 | |
---|
18 | The directives provided by the thread manager are: |
---|
19 | |
---|
20 | @itemize @bullet |
---|
21 | @item @code{pthread_attr_init} - Initialize a Thread Attribute Set |
---|
22 | @item @code{pthread_attr_destroy} - Destroy a Thread Attribute Set |
---|
23 | @item @code{pthread_attr_setdetachstate} - Set Detach State |
---|
24 | @item @code{pthread_attr_getdetachstate} - Get Detach State |
---|
25 | @item @code{pthread_attr_setstacksize} - Set Thread Stack Size |
---|
26 | @item @code{pthread_attr_getstacksize} - Get Thread Stack Size |
---|
27 | @item @code{pthread_attr_setstackaddr} - Set Thread Stack Address |
---|
28 | @item @code{pthread_attr_getstackaddr} - Get Thread Stack Address |
---|
29 | @item @code{pthread_attr_setscope} - Set Thread Scheduling Scope |
---|
30 | @item @code{pthread_attr_getscope} - Get Thread Scheduling Scope |
---|
31 | @item @code{pthread_attr_setinheritsched} - Set Inherit Scheduler Flag |
---|
32 | @item @code{pthread_attr_getinheritsched} - Get Inherit Scheduler Flag |
---|
33 | @item @code{pthread_attr_setschedpolicy} - Set Scheduling Policy |
---|
34 | @item @code{pthread_attr_getschedpolicy} - Get Scheduling Policy |
---|
35 | @item @code{pthread_attr_setschedparam} - Set Scheduling Parameters |
---|
36 | @item @code{pthread_attr_getschedparam} - Get Scheduling Parameters |
---|
37 | @item @code{pthread_create} - Create a Thread |
---|
38 | @item @code{pthread_exit} - Terminate the Current Thread |
---|
39 | @item @code{pthread_detach} - Detach a Thread |
---|
40 | @item @code{pthread_join} - Wait for Thread Termination |
---|
41 | @item @code{pthread_self} - Get Thread ID |
---|
42 | @item @code{pthread_equal} - Compare Thread IDs |
---|
43 | @item @code{pthread_once} - Dynamic Package Initialization |
---|
44 | @item @code{pthread_setschedparam} - Set Thread Scheduling Parameters |
---|
45 | @item @code{pthread_getschedparam} - Get Thread Scheduling Parameters |
---|
46 | @end itemize |
---|
47 | |
---|
48 | @section Background |
---|
49 | |
---|
50 | @subsection Thread Attributes |
---|
51 | |
---|
52 | Thread attributes are utilized only at thread creation time. A thread |
---|
53 | attribute structure may be initialized and passed as an argument to |
---|
54 | the @code{pthread_create} routine. |
---|
55 | |
---|
56 | @table @b |
---|
57 | @item stack address |
---|
58 | is the address of the optionally user specified stack area for this thread. |
---|
59 | If this value is NULL, then RTEMS allocates the memory for the thread stack |
---|
60 | from the RTEMS Workspace Area. Otherwise, this is the user specified |
---|
61 | address for the memory to be used for the thread's stack. Each thread must |
---|
62 | have a distinct stack area. Each processor family has different alignment |
---|
63 | rules which should be followed. |
---|
64 | |
---|
65 | @item stack size |
---|
66 | is the minimum desired size for this thread's stack area. |
---|
67 | If the size of this area as specified by the stack size attribute |
---|
68 | is smaller than the minimum for this processor family and the stack |
---|
69 | is not user specified, then RTEMS will automatically allocate a |
---|
70 | stack of the minimum size for this processor family. |
---|
71 | |
---|
72 | @item contention scope |
---|
73 | specifies the scheduling contention scope. RTEMS only supports the |
---|
74 | PTHREAD_SCOPE_PROCESS scheduling contention scope. |
---|
75 | |
---|
76 | @item scheduling inheritance |
---|
77 | specifies whether a user specified or the scheduling policy and |
---|
78 | parameters of the currently executing thread are to be used. When |
---|
79 | this is PTHREAD_INHERIT_SCHED, then the scheduling policy and |
---|
80 | parameters of the currently executing thread are inherited by |
---|
81 | the newly created thread. |
---|
82 | |
---|
83 | @item scheduling policy and parameters |
---|
84 | specify the manner in which the thread will contend for the processor. |
---|
85 | The scheduling parameters are interpreted based on the specified policy. |
---|
86 | All policies utilize the thread priority parameter. |
---|
87 | |
---|
88 | @end table |
---|
89 | |
---|
90 | @section Operations |
---|
91 | |
---|
92 | There is currently no text in this section. |
---|
93 | |
---|
94 | @section Directives |
---|
95 | |
---|
96 | This section details the thread manager's directives. |
---|
97 | A subsection is dedicated to each of this manager's directives |
---|
98 | and describes the calling sequence, related constants, usage, |
---|
99 | and status codes. |
---|
100 | |
---|
101 | @page |
---|
102 | @subsection pthread_attr_init - Initialize a Thread Attribute Set |
---|
103 | |
---|
104 | @subheading CALLING SEQUENCE: |
---|
105 | |
---|
106 | |
---|
107 | @example |
---|
108 | #include <pthread.h> |
---|
109 | |
---|
110 | int pthread_attr_init( |
---|
111 | pthread_attr_t *attr |
---|
112 | ); |
---|
113 | @end example |
---|
114 | |
---|
115 | @subheading STATUS CODES: |
---|
116 | |
---|
117 | @table @b |
---|
118 | @item EINVAL |
---|
119 | The attribute pointer argument is invalid. |
---|
120 | |
---|
121 | @end table |
---|
122 | |
---|
123 | @subheading DESCRIPTION: |
---|
124 | |
---|
125 | The @code{pthread_attr_init} routine initializes the thread attributes |
---|
126 | object specified by @code{attr} with the default value for all of the |
---|
127 | individual attributes. |
---|
128 | |
---|
129 | @subheading NOTES: |
---|
130 | |
---|
131 | The settings in the default attributes are implementation defined. For |
---|
132 | RTEMS, the default attributes are as follows: |
---|
133 | |
---|
134 | @itemize @bullet |
---|
135 | |
---|
136 | @item stackadr |
---|
137 | is not set to indicate that RTEMS is to allocate the stack memory. |
---|
138 | |
---|
139 | @item stacksize |
---|
140 | is set to @code{PTHREAD_MINIMUM_STACK_SIZE}. |
---|
141 | |
---|
142 | @item contentionscope |
---|
143 | is set to @code{PTHREAD_SCOPE_PROCESS}. |
---|
144 | |
---|
145 | @item inheritsched |
---|
146 | is set to @code{PTHREAD_INHERIT_SCHED} to indicate that the created |
---|
147 | thread inherits its scheduling attributes from its parent. |
---|
148 | |
---|
149 | @item detachstate |
---|
150 | is set to @code{PTHREAD_CREATE_JOINABLE}. |
---|
151 | |
---|
152 | @end itemize |
---|
153 | |
---|
154 | |
---|
155 | @page |
---|
156 | @subsection pthread_attr_destroy - Destroy a Thread Attribute Set |
---|
157 | |
---|
158 | @subheading CALLING SEQUENCE: |
---|
159 | |
---|
160 | @example |
---|
161 | #include <pthread.h> |
---|
162 | |
---|
163 | int pthread_attr_destroy( |
---|
164 | pthread_attr_t *attr |
---|
165 | ); |
---|
166 | @end example |
---|
167 | |
---|
168 | @subheading STATUS CODES: |
---|
169 | |
---|
170 | @table @b |
---|
171 | @item EINVAL |
---|
172 | The attribute pointer argument is invalid. |
---|
173 | |
---|
174 | @item EINVAL |
---|
175 | The attribute set is not initialized. |
---|
176 | |
---|
177 | @end table |
---|
178 | |
---|
179 | @subheading DESCRIPTION: |
---|
180 | |
---|
181 | The @code{pthread_attr_destroy} routine is used to destroy a thread |
---|
182 | attributes object. The behavior of using an attributes object after |
---|
183 | it is destroyed is implementation dependent. |
---|
184 | |
---|
185 | @subheading NOTES: |
---|
186 | |
---|
187 | NONE |
---|
188 | |
---|
189 | @page |
---|
190 | @subsection pthread_attr_setdetachstate - Set Detach State |
---|
191 | |
---|
192 | @subheading CALLING SEQUENCE: |
---|
193 | |
---|
194 | @example |
---|
195 | #include <pthread.h> |
---|
196 | |
---|
197 | int pthread_attr_setdetachstate( |
---|
198 | pthread_attr_t *attr, |
---|
199 | int detachstate |
---|
200 | ); |
---|
201 | @end example |
---|
202 | |
---|
203 | @subheading STATUS CODES: |
---|
204 | |
---|
205 | @table @b |
---|
206 | @item EINVAL |
---|
207 | The attribute pointer argument is invalid. |
---|
208 | |
---|
209 | @item EINVAL |
---|
210 | The attribute set is not initialized. |
---|
211 | |
---|
212 | @item EINVAL |
---|
213 | The detachstate argument is invalid. |
---|
214 | |
---|
215 | @end table |
---|
216 | |
---|
217 | @subheading DESCRIPTION: |
---|
218 | |
---|
219 | The @code{pthread_attr_setdetachstate} routine is used to value of the |
---|
220 | @code{detachstate} attribute. This attribute controls whether the |
---|
221 | thread is created in a detached state. |
---|
222 | |
---|
223 | The @code{detachstate} can be either @code{PTHREAD_CREATE_DETACHED} or |
---|
224 | @code{PTHREAD_CREATE_JOINABLE}. The default value for all threads is |
---|
225 | @code{PTHREAD_CREATE_JOINABLE}. |
---|
226 | |
---|
227 | @subheading NOTES: |
---|
228 | |
---|
229 | If a thread is in a detached state, |
---|
230 | then the use of the ID with the @code{pthread_detach} or |
---|
231 | @code{pthread_join} routines is an error. |
---|
232 | |
---|
233 | @page |
---|
234 | @subsection pthread_attr_getdetachstate - Get Detach State |
---|
235 | |
---|
236 | @subheading CALLING SEQUENCE: |
---|
237 | |
---|
238 | @example |
---|
239 | #include <pthread.h> |
---|
240 | |
---|
241 | int pthread_attr_getdetachstate( |
---|
242 | const pthread_attr_t *attr, |
---|
243 | int *detachstate |
---|
244 | ); |
---|
245 | @end example |
---|
246 | |
---|
247 | @subheading STATUS CODES: |
---|
248 | |
---|
249 | @table @b |
---|
250 | @item EINVAL |
---|
251 | The attribute pointer argument is invalid. |
---|
252 | |
---|
253 | @item EINVAL |
---|
254 | The attribute set is not initialized. |
---|
255 | |
---|
256 | @item EINVAL |
---|
257 | The detatchstate pointer argument is invalid. |
---|
258 | |
---|
259 | @end table |
---|
260 | |
---|
261 | @subheading DESCRIPTION: |
---|
262 | |
---|
263 | The @code{pthread_attr_getdetachstate} routine is used to obtain the |
---|
264 | current value of the @code{detachstate} attribute as specified |
---|
265 | by the @code{attr} thread attribute object. |
---|
266 | |
---|
267 | @subheading NOTES: |
---|
268 | |
---|
269 | NONE |
---|
270 | |
---|
271 | @page |
---|
272 | @subsection pthread_attr_setstacksize - Set Thread Stack Size |
---|
273 | |
---|
274 | @subheading CALLING SEQUENCE: |
---|
275 | |
---|
276 | @example |
---|
277 | #include <pthread.h> |
---|
278 | |
---|
279 | int pthread_attr_setstacksize( |
---|
280 | pthread_attr_t *attr, |
---|
281 | size_t stacksize |
---|
282 | ); |
---|
283 | @end example |
---|
284 | |
---|
285 | @subheading STATUS CODES: |
---|
286 | |
---|
287 | @table @b |
---|
288 | @item EINVAL |
---|
289 | The attribute pointer argument is invalid. |
---|
290 | |
---|
291 | @item EINVAL |
---|
292 | The attribute set is not initialized. |
---|
293 | |
---|
294 | @end table |
---|
295 | |
---|
296 | @subheading DESCRIPTION: |
---|
297 | |
---|
298 | The @code{pthread_attr_setstacksize} routine is used to set the |
---|
299 | @code{stacksize} attribute in the @code{attr} thread attribute |
---|
300 | object. |
---|
301 | |
---|
302 | @subheading NOTES: |
---|
303 | |
---|
304 | As required by POSIX, RTEMS defines the feature symbol |
---|
305 | @code{_POSIX_THREAD_ATTR_STACKSIZE} to indicate that this |
---|
306 | routine is supported. |
---|
307 | |
---|
308 | If the specified stacksize is below the minimum required for this CPU |
---|
309 | (@code{PTHREAD_STACK_MIN}, then the stacksize will be set to the minimum |
---|
310 | for this CPU. |
---|
311 | |
---|
312 | @page |
---|
313 | @subsection pthread_attr_getstacksize - Get Thread Stack Size |
---|
314 | |
---|
315 | @subheading CALLING SEQUENCE: |
---|
316 | |
---|
317 | @example |
---|
318 | #include <pthread.h> |
---|
319 | |
---|
320 | int pthread_attr_getstacksize( |
---|
321 | const pthread_attr_t *attr, |
---|
322 | size_t *stacksize |
---|
323 | ); |
---|
324 | @end example |
---|
325 | |
---|
326 | @subheading STATUS CODES: |
---|
327 | |
---|
328 | @table @b |
---|
329 | @item EINVAL |
---|
330 | The attribute pointer argument is invalid. |
---|
331 | |
---|
332 | @item EINVAL |
---|
333 | The attribute set is not initialized. |
---|
334 | |
---|
335 | @item EINVAL |
---|
336 | The stacksize pointer argument is invalid. |
---|
337 | |
---|
338 | @end table |
---|
339 | |
---|
340 | @subheading DESCRIPTION: |
---|
341 | |
---|
342 | The @code{pthread_attr_getstacksize} routine is used to obtain the |
---|
343 | @code{stacksize} attribute in the @code{attr} thread attribute |
---|
344 | object. |
---|
345 | |
---|
346 | @subheading NOTES: |
---|
347 | |
---|
348 | As required by POSIX, RTEMS defines the feature symbol |
---|
349 | @code{_POSIX_THREAD_ATTR_STACKSIZE} to indicate that this |
---|
350 | routine is supported. |
---|
351 | |
---|
352 | @page |
---|
353 | @subsection pthread_attr_setstackaddr - Set Thread Stack Address |
---|
354 | |
---|
355 | @subheading CALLING SEQUENCE: |
---|
356 | |
---|
357 | @example |
---|
358 | #include <pthread.h> |
---|
359 | |
---|
360 | int pthread_attr_setstackaddr( |
---|
361 | pthread_attr_t *attr, |
---|
362 | void *stackaddr |
---|
363 | ); |
---|
364 | @end example |
---|
365 | |
---|
366 | @subheading STATUS CODES: |
---|
367 | |
---|
368 | @table @b |
---|
369 | @item EINVAL |
---|
370 | The attribute pointer argument is invalid. |
---|
371 | |
---|
372 | @item EINVAL |
---|
373 | The attribute set is not initialized. |
---|
374 | |
---|
375 | @end table |
---|
376 | |
---|
377 | @subheading DESCRIPTION: |
---|
378 | |
---|
379 | The @code{pthread_attr_setstackaddr} routine is used to set the |
---|
380 | @code{stackaddr} attribute in the @code{attr} thread attribute |
---|
381 | object. |
---|
382 | |
---|
383 | @subheading NOTES: |
---|
384 | |
---|
385 | As required by POSIX, RTEMS defines the feature symbol |
---|
386 | @code{_POSIX_THREAD_ATTR_STACKADDR} to indicate that this |
---|
387 | routine is supported. |
---|
388 | |
---|
389 | It is imperative to the proper operation of the system that |
---|
390 | each thread have sufficient stack space. |
---|
391 | |
---|
392 | @page |
---|
393 | @subsection pthread_attr_getstackaddr - Get Thread Stack Address |
---|
394 | |
---|
395 | @subheading CALLING SEQUENCE: |
---|
396 | |
---|
397 | @example |
---|
398 | #include <pthread.h> |
---|
399 | |
---|
400 | int pthread_attr_getstackaddr( |
---|
401 | const pthread_attr_t *attr, |
---|
402 | void **stackaddr |
---|
403 | ); |
---|
404 | @end example |
---|
405 | |
---|
406 | @subheading STATUS CODES: |
---|
407 | |
---|
408 | @table @b |
---|
409 | @item EINVAL |
---|
410 | The attribute pointer argument is invalid. |
---|
411 | |
---|
412 | @item EINVAL |
---|
413 | The attribute set is not initialized. |
---|
414 | |
---|
415 | @item EINVAL |
---|
416 | The stackaddr pointer argument is invalid. |
---|
417 | |
---|
418 | @end table |
---|
419 | |
---|
420 | @subheading DESCRIPTION: |
---|
421 | |
---|
422 | The @code{pthread_attr_getstackaddr} routine is used to obtain the |
---|
423 | @code{stackaddr} attribute in the @code{attr} thread attribute |
---|
424 | object. |
---|
425 | |
---|
426 | @subheading NOTES: |
---|
427 | |
---|
428 | As required by POSIX, RTEMS defines the feature symbol |
---|
429 | @code{_POSIX_THREAD_ATTR_STACKADDR} to indicate that this |
---|
430 | routine is supported. |
---|
431 | |
---|
432 | @page |
---|
433 | @subsection pthread_attr_setscope - Set Thread Scheduling Scope |
---|
434 | |
---|
435 | @subheading CALLING SEQUENCE: |
---|
436 | |
---|
437 | @example |
---|
438 | #include <pthread.h> |
---|
439 | |
---|
440 | int pthread_attr_setscope( |
---|
441 | pthread_attr_t *attr, |
---|
442 | int contentionscope |
---|
443 | ); |
---|
444 | @end example |
---|
445 | |
---|
446 | @subheading STATUS CODES: |
---|
447 | |
---|
448 | @table @b |
---|
449 | @item EINVAL |
---|
450 | The attribute pointer argument is invalid. |
---|
451 | |
---|
452 | @item EINVAL |
---|
453 | The attribute set is not initialized. |
---|
454 | |
---|
455 | @item EINVAL |
---|
456 | The contention scope specified is not valid. |
---|
457 | |
---|
458 | @item ENOTSUP |
---|
459 | The contention scope specified (PTHREAD_SCOPE_SYSTEM) is not supported. |
---|
460 | |
---|
461 | @end table |
---|
462 | |
---|
463 | @subheading DESCRIPTION: |
---|
464 | |
---|
465 | The @code{pthread_attr_setscope} routine is used to set the contention |
---|
466 | scope field in the thread attribute object @code{attr} to the value |
---|
467 | specified by @code{contentionscope}. |
---|
468 | |
---|
469 | The @code{contentionscope} must be either @code{PTHREAD_SCOPE_SYSTEM} |
---|
470 | to indicate that the thread is to be within system scheduling contention |
---|
471 | or @code{PTHREAD_SCOPE_PROCESS} indicating that the thread is to be |
---|
472 | within the process scheduling contention scope. |
---|
473 | |
---|
474 | @subheading NOTES: |
---|
475 | |
---|
476 | As required by POSIX, RTEMS defines the feature symbol |
---|
477 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
478 | family of routines to which this routine belongs is supported. |
---|
479 | |
---|
480 | @page |
---|
481 | @subsection pthread_attr_getscope - Get Thread Scheduling Scope |
---|
482 | |
---|
483 | @subheading CALLING SEQUENCE: |
---|
484 | |
---|
485 | @example |
---|
486 | #include <pthread.h> |
---|
487 | |
---|
488 | int pthread_attr_getscope( |
---|
489 | const pthread_attr_t *attr, |
---|
490 | int *contentionscope |
---|
491 | ); |
---|
492 | @end example |
---|
493 | |
---|
494 | @subheading STATUS CODES: |
---|
495 | |
---|
496 | @table @b |
---|
497 | @item EINVAL |
---|
498 | The attribute pointer argument is invalid. |
---|
499 | |
---|
500 | @item EINVAL |
---|
501 | The attribute set is not initialized. |
---|
502 | |
---|
503 | @item EINVAL |
---|
504 | The contentionscope pointer argument is invalid. |
---|
505 | |
---|
506 | @end table |
---|
507 | |
---|
508 | @subheading DESCRIPTION: |
---|
509 | |
---|
510 | The @code{pthread_attr_getscope} routine is used to obtain the |
---|
511 | value of the contention scope field in the thread attributes |
---|
512 | object @code{attr}. The current value is returned in |
---|
513 | @code{contentionscope}. |
---|
514 | |
---|
515 | @subheading NOTES: |
---|
516 | |
---|
517 | As required by POSIX, RTEMS defines the feature symbol |
---|
518 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
519 | family of routines to which this routine belongs is supported. |
---|
520 | @page |
---|
521 | @subsection pthread_attr_setinheritsched - Set Inherit Scheduler Flag |
---|
522 | |
---|
523 | @subheading CALLING SEQUENCE: |
---|
524 | |
---|
525 | @example |
---|
526 | #include <pthread.h> |
---|
527 | |
---|
528 | int pthread_attr_setinheritsched( |
---|
529 | pthread_attr_t *attr, |
---|
530 | int inheritsched |
---|
531 | ); |
---|
532 | @end example |
---|
533 | |
---|
534 | @subheading STATUS CODES: |
---|
535 | |
---|
536 | @table @b |
---|
537 | @item EINVAL |
---|
538 | The attribute pointer argument is invalid. |
---|
539 | |
---|
540 | @item EINVAL |
---|
541 | The attribute set is not initialized. |
---|
542 | |
---|
543 | @item EINVAL |
---|
544 | The specified scheduler inheritance argument is invalid. |
---|
545 | |
---|
546 | @end table |
---|
547 | |
---|
548 | @subheading DESCRIPTION: |
---|
549 | |
---|
550 | The @code{pthread_attr_setinheritsched} routine is used to set the |
---|
551 | inherit scheduler field in the thread attribute object @code{attr} to |
---|
552 | the value specified by @code{inheritsched}. |
---|
553 | |
---|
554 | The @code{contentionscope} must be either @code{PTHREAD_INHERIT_SCHED} |
---|
555 | to indicate that the thread is to inherit the scheduling policy |
---|
556 | and parameters fromthe creating thread, or @code{PTHREAD_EXPLICIT_SCHED} |
---|
557 | to indicate that the scheduling policy and parameters for this thread |
---|
558 | are to be set from the corresponding values in the attributes object. |
---|
559 | If @code{contentionscope} is @code{PTHREAD_INHERIT_SCHED}, then the |
---|
560 | scheduling attributes in the @code{attr} structure will be ignored |
---|
561 | at thread creation time. |
---|
562 | |
---|
563 | @subheading NOTES: |
---|
564 | |
---|
565 | As required by POSIX, RTEMS defines the feature symbol |
---|
566 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
567 | family of routines to which this routine belongs is supported. |
---|
568 | |
---|
569 | @page |
---|
570 | @subsection pthread_attr_getinheritsched - Get Inherit Scheduler Flag |
---|
571 | |
---|
572 | @subheading CALLING SEQUENCE: |
---|
573 | |
---|
574 | @example |
---|
575 | #include <pthread.h> |
---|
576 | |
---|
577 | int pthread_attr_getinheritsched( |
---|
578 | const pthread_attr_t *attr, |
---|
579 | int *inheritsched |
---|
580 | ); |
---|
581 | @end example |
---|
582 | |
---|
583 | @subheading STATUS CODES: |
---|
584 | @table @b |
---|
585 | @item EINVAL |
---|
586 | The attribute pointer argument is invalid. |
---|
587 | |
---|
588 | @item EINVAL |
---|
589 | The attribute set is not initialized. |
---|
590 | |
---|
591 | @item EINVAL |
---|
592 | The inheritsched pointer argument is invalid. |
---|
593 | |
---|
594 | @end table |
---|
595 | |
---|
596 | @subheading DESCRIPTION: |
---|
597 | |
---|
598 | The @code{pthread_attr_getinheritsched} routine is used to |
---|
599 | object the current value of the inherit scheduler field in |
---|
600 | the thread attribute object @code{attr}. |
---|
601 | |
---|
602 | @subheading NOTES: |
---|
603 | |
---|
604 | As required by POSIX, RTEMS defines the feature symbol |
---|
605 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
606 | family of routines to which this routine belongs is supported. |
---|
607 | |
---|
608 | @page |
---|
609 | @subsection pthread_attr_setschedpolicy - Set Scheduling Policy |
---|
610 | |
---|
611 | @subheading CALLING SEQUENCE: |
---|
612 | |
---|
613 | @example |
---|
614 | #include <pthread.h> |
---|
615 | |
---|
616 | int pthread_attr_setschedpolicy( |
---|
617 | pthread_attr_t *attr, |
---|
618 | int policy |
---|
619 | ); |
---|
620 | @end example |
---|
621 | |
---|
622 | @subheading STATUS CODES: |
---|
623 | @table @b |
---|
624 | @item EINVAL |
---|
625 | The attribute pointer argument is invalid. |
---|
626 | |
---|
627 | @item EINVAL |
---|
628 | The attribute set is not initialized. |
---|
629 | |
---|
630 | @item ENOTSUP |
---|
631 | The specified scheduler policy argument is invalid. |
---|
632 | |
---|
633 | @end table |
---|
634 | |
---|
635 | @subheading DESCRIPTION: |
---|
636 | |
---|
637 | The @code{pthread_attr_setschedpolicy} routine is used to set the |
---|
638 | scheduler policy field in the thread attribute object @code{attr} to |
---|
639 | the value specified by @code{policy}. |
---|
640 | |
---|
641 | Scheduling policies may be one of the following: |
---|
642 | |
---|
643 | @itemize @bullet |
---|
644 | |
---|
645 | @item @code{SCHED_DEFAULT} |
---|
646 | @item @code{SCHED_FIFO} |
---|
647 | @item @code{SCHED_RR} |
---|
648 | @item @code{SCHED_SPORADIC} |
---|
649 | @item @code{SCHED_OTHER} |
---|
650 | |
---|
651 | @end itemize |
---|
652 | |
---|
653 | The precise meaning of each of these is discussed elsewhere in this |
---|
654 | manual. |
---|
655 | |
---|
656 | @subheading NOTES: |
---|
657 | |
---|
658 | As required by POSIX, RTEMS defines the feature symbol |
---|
659 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
660 | family of routines to which this routine belongs is supported. |
---|
661 | |
---|
662 | @page |
---|
663 | @subsection pthread_attr_getschedpolicy - Get Scheduling Policy |
---|
664 | |
---|
665 | @subheading CALLING SEQUENCE: |
---|
666 | |
---|
667 | @example |
---|
668 | #include <pthread.h> |
---|
669 | |
---|
670 | int pthread_attr_getschedpolicy( |
---|
671 | const pthread_attr_t *attr, |
---|
672 | int *policy |
---|
673 | ); |
---|
674 | @end example |
---|
675 | |
---|
676 | @subheading STATUS CODES: |
---|
677 | @table @b |
---|
678 | @item EINVAL |
---|
679 | The attribute pointer argument is invalid. |
---|
680 | |
---|
681 | @item EINVAL |
---|
682 | The attribute set is not initialized. |
---|
683 | |
---|
684 | @item EINVAL |
---|
685 | The specified scheduler policy argument pointer is invalid. |
---|
686 | |
---|
687 | @end table |
---|
688 | |
---|
689 | @subheading DESCRIPTION: |
---|
690 | |
---|
691 | The @code{pthread_attr_getschedpolicy} routine is used to obtain the |
---|
692 | scheduler policy field from the thread attribute object @code{attr}. |
---|
693 | The value of this field is returned in @code{policy}. |
---|
694 | |
---|
695 | @subheading NOTES: |
---|
696 | |
---|
697 | As required by POSIX, RTEMS defines the feature symbol |
---|
698 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
699 | family of routines to which this routine belongs is supported. |
---|
700 | |
---|
701 | @page |
---|
702 | @subsection pthread_attr_setschedparam - Set Scheduling Parameters |
---|
703 | |
---|
704 | @subheading CALLING SEQUENCE: |
---|
705 | |
---|
706 | @example |
---|
707 | #include <pthread.h> |
---|
708 | |
---|
709 | int pthread_attr_setschedparam( |
---|
710 | pthread_attr_t *attr, |
---|
711 | const struct sched_param param |
---|
712 | ); |
---|
713 | @end example |
---|
714 | |
---|
715 | @subheading STATUS CODES: |
---|
716 | @table @b |
---|
717 | @item EINVAL |
---|
718 | The attribute pointer argument is invalid. |
---|
719 | |
---|
720 | @item EINVAL |
---|
721 | The attribute set is not initialized. |
---|
722 | |
---|
723 | @item EINVAL |
---|
724 | The specified scheduler parameter argument is invalid. |
---|
725 | |
---|
726 | @end table |
---|
727 | |
---|
728 | @subheading DESCRIPTION: |
---|
729 | |
---|
730 | The @code{pthread_attr_setschedparam} routine is used to set the |
---|
731 | scheduler parameters field in the thread attribute object @code{attr} to |
---|
732 | the value specified by @code{param}. |
---|
733 | |
---|
734 | @subheading NOTES: |
---|
735 | |
---|
736 | As required by POSIX, RTEMS defines the feature symbol |
---|
737 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
738 | family of routines to which this routine belongs is supported. |
---|
739 | |
---|
740 | @page |
---|
741 | @subsection pthread_attr_getschedparam - Get Scheduling Parameters |
---|
742 | |
---|
743 | @subheading CALLING SEQUENCE: |
---|
744 | |
---|
745 | @example |
---|
746 | #include <pthread.h> |
---|
747 | |
---|
748 | int pthread_attr_getschedparam( |
---|
749 | const pthread_attr_t *attr, |
---|
750 | struct sched_param *param |
---|
751 | ); |
---|
752 | @end example |
---|
753 | |
---|
754 | @subheading STATUS CODES: |
---|
755 | @table @b |
---|
756 | @item EINVAL |
---|
757 | The attribute pointer argument is invalid. |
---|
758 | |
---|
759 | @item EINVAL |
---|
760 | The attribute set is not initialized. |
---|
761 | |
---|
762 | @item EINVAL |
---|
763 | The specified scheduler parameter argument pointer is invalid. |
---|
764 | |
---|
765 | @end table |
---|
766 | |
---|
767 | @subheading DESCRIPTION: |
---|
768 | |
---|
769 | The @code{pthread_attr_getschedparam} routine is used to obtain the |
---|
770 | scheduler parameters field from the thread attribute object @code{attr}. |
---|
771 | The value of this field is returned in @code{param}. |
---|
772 | |
---|
773 | @subheading NOTES: |
---|
774 | |
---|
775 | As required by POSIX, RTEMS defines the feature symbol |
---|
776 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
777 | family of routines to which this routine belongs is supported. |
---|
778 | |
---|
779 | @page |
---|
780 | @subsection pthread_create - Create a Thread |
---|
781 | |
---|
782 | @subheading CALLING SEQUENCE: |
---|
783 | |
---|
784 | @example |
---|
785 | #include <pthread.h> |
---|
786 | |
---|
787 | int pthread_create( |
---|
788 | pthread_t *thread, |
---|
789 | const pthread_attr_t *attr, |
---|
790 | void (*start_routine)( void * ), |
---|
791 | void *arg |
---|
792 | ); |
---|
793 | @end example |
---|
794 | |
---|
795 | @subheading STATUS CODES: |
---|
796 | |
---|
797 | @table @b |
---|
798 | |
---|
799 | @item EINVAL |
---|
800 | The attribute set is not initialized. |
---|
801 | |
---|
802 | @item EINVAL |
---|
803 | The user specified a stack address and the size of the area was not |
---|
804 | large enough to meet this processor's minimum stack requirements. |
---|
805 | |
---|
806 | @item EINVAL |
---|
807 | The specified scheduler inheritance policy was invalid. |
---|
808 | |
---|
809 | @item ENOTSUP |
---|
810 | The specified contention scope was PTHREAD_SCOPE_PROCESS. |
---|
811 | |
---|
812 | @item EINVAL |
---|
813 | The specified thread priority was invalid. |
---|
814 | |
---|
815 | @item EINVAL |
---|
816 | The specified scheduling policy was invalid. |
---|
817 | |
---|
818 | @item EINVAL |
---|
819 | The scheduling policy was SCHED_SPORADIC and the specified replenishment |
---|
820 | period is less than the initial budget. |
---|
821 | |
---|
822 | @item EINVAL |
---|
823 | The scheduling policy was SCHED_SPORADIC and the specified low priority |
---|
824 | is invalid. |
---|
825 | |
---|
826 | @item EAGAIN |
---|
827 | The system lacked the necessary resources to create another thread, or the |
---|
828 | self imposed limit on the total number of threads in a process |
---|
829 | PTHREAD_THREAD_MAX would be exceeded. |
---|
830 | |
---|
831 | @item EINVAL |
---|
832 | Invalid argument passed. |
---|
833 | |
---|
834 | @end table |
---|
835 | |
---|
836 | @subheading DESCRIPTION: |
---|
837 | |
---|
838 | The @code{pthread_create} routine is used to create a new thread with |
---|
839 | the attributes specified by @code{attr}. If the @code{attr} argument |
---|
840 | is @code{NULL}, then the default attribute set will be used. Modification |
---|
841 | of the contents of @code{attr} after this thread is created does not |
---|
842 | have an impact on this thread. |
---|
843 | |
---|
844 | The thread begins execution at the address specified by @code{start_routine} |
---|
845 | with @code{arg} as its only argument. If @code{start_routine} returns, |
---|
846 | then it is functionally equivalent to the thread executing the |
---|
847 | @code{pthread_exit} service. |
---|
848 | |
---|
849 | Upon successful completion, the ID of the created thread is returned in the |
---|
850 | @code{thread} argument. |
---|
851 | |
---|
852 | @subheading NOTES: |
---|
853 | |
---|
854 | There is no concept of a single main thread in RTEMS as there is in |
---|
855 | a tradition UNIX system. POSIX requires that the implicit return of |
---|
856 | the main thread results in the same effects as if there were a call |
---|
857 | to @code{exit}. This does not occur in RTEMS. |
---|
858 | |
---|
859 | The signal mask of the newly created thread is inherited from its |
---|
860 | creator and the set of pending signals for this thread is empty. |
---|
861 | |
---|
862 | @page |
---|
863 | @subsection pthread_exit - Terminate the Current Thread |
---|
864 | |
---|
865 | @subheading CALLING SEQUENCE: |
---|
866 | |
---|
867 | @example |
---|
868 | #include <pthread.h> |
---|
869 | |
---|
870 | void pthread_exit( |
---|
871 | void *status |
---|
872 | ); |
---|
873 | @end example |
---|
874 | |
---|
875 | @subheading STATUS CODES: |
---|
876 | @table @b |
---|
877 | @item NONE |
---|
878 | |
---|
879 | @end table |
---|
880 | |
---|
881 | @subheading DESCRIPTION: |
---|
882 | |
---|
883 | The @code{pthread_exit} routine is used to temrinate the calling thread. |
---|
884 | The @code{status} is made available to any successful join with the |
---|
885 | terminating thread. |
---|
886 | |
---|
887 | When a thread returns from its start routine, it results in an |
---|
888 | implicit call to the @code{pthread_exit} routine with the return |
---|
889 | value of the function serving as the argument to @code{pthread_exit}. |
---|
890 | |
---|
891 | @subheading NOTES: |
---|
892 | |
---|
893 | Any cancellation cleanup handlers that hace been pushed and not yet popped |
---|
894 | shall be popped in reverse of the order that they were pushed. After |
---|
895 | all cancellation cleanup handlers have been executed, if the |
---|
896 | thread has any thread-specific data, destructors for that data will |
---|
897 | be invoked. |
---|
898 | |
---|
899 | Thread termination does not release or free any application visible |
---|
900 | resources including byt not limited to mutexes, file descriptors, allocated |
---|
901 | memory, etc.. Similarly, exitting a thread does not result in any |
---|
902 | process-oriented cleanup activity. |
---|
903 | |
---|
904 | There is no concept of a single main thread in RTEMS as there is in |
---|
905 | a tradition UNIX system. POSIX requires that the implicit return of |
---|
906 | the main thread results in the same effects as if there were a call |
---|
907 | to @code{exit}. This does not occur in RTEMS. |
---|
908 | |
---|
909 | All access to any automatic variables allocated by the threads is lost |
---|
910 | when the thread exits. Thus references (i.e. pointers) to local variables |
---|
911 | of a thread should not be used in a global manner without care. As |
---|
912 | a specific example, a pointer to a local variable should NOT be used |
---|
913 | as the return value. |
---|
914 | |
---|
915 | |
---|
916 | @page |
---|
917 | @subsection pthread_detach - Detach a Thread |
---|
918 | |
---|
919 | @subheading CALLING SEQUENCE: |
---|
920 | |
---|
921 | @example |
---|
922 | #include <pthread.h> |
---|
923 | |
---|
924 | int pthread_detach( |
---|
925 | pthread_t thread |
---|
926 | ); |
---|
927 | @end example |
---|
928 | |
---|
929 | @subheading STATUS CODES: |
---|
930 | @table @b |
---|
931 | @item ESRCH |
---|
932 | The thread specified is invalid. |
---|
933 | |
---|
934 | @item EINVAL |
---|
935 | The thread specified is not a joinable thread. |
---|
936 | |
---|
937 | @end table |
---|
938 | |
---|
939 | @subheading DESCRIPTION: |
---|
940 | |
---|
941 | The @code{pthread_detach} routine is used to to indicate that storage |
---|
942 | for @code{thread} can be reclaimed when the thread terminates without |
---|
943 | another thread joinging with it. |
---|
944 | |
---|
945 | @subheading NOTES: |
---|
946 | |
---|
947 | If any threads have previously joined with the specified thread, then they |
---|
948 | will remain joined with that thread. Any subsequent calls to |
---|
949 | @code{pthread_join} on the specified thread will fail. |
---|
950 | |
---|
951 | @page |
---|
952 | @subsection pthread_join - Wait for Thread Termination |
---|
953 | |
---|
954 | @subheading CALLING SEQUENCE: |
---|
955 | |
---|
956 | @example |
---|
957 | #include <pthread.h> |
---|
958 | |
---|
959 | int pthread_join( |
---|
960 | pthread_t thread, |
---|
961 | void **value_ptr |
---|
962 | ); |
---|
963 | @end example |
---|
964 | |
---|
965 | @subheading STATUS CODES: |
---|
966 | @table @b |
---|
967 | @item ESRCH |
---|
968 | The thread specified is invalid. |
---|
969 | |
---|
970 | @item EINVAL |
---|
971 | The thread specified is not a joinable thread. |
---|
972 | |
---|
973 | @item EDEADLK |
---|
974 | A deadlock was detected or thread is the calling thread. |
---|
975 | |
---|
976 | @end table |
---|
977 | |
---|
978 | @subheading DESCRIPTION: |
---|
979 | |
---|
980 | The @code{pthread_join} routine suspends execution of the calling thread |
---|
981 | until @code{thread} terminates. If @code{thread} has already terminated, |
---|
982 | then this routine returns immediately. The value returned by @code{thread} |
---|
983 | (i.e. passed to @code{pthread_exit} is returned in @code{value_ptr}. |
---|
984 | |
---|
985 | When this routine returns, then @code{thread} has been temrinated. |
---|
986 | |
---|
987 | @subheading NOTES: |
---|
988 | |
---|
989 | The results of multiple simultaneous joins on the same thread is undefined. |
---|
990 | |
---|
991 | If any threads have previously joined with the specified thread, then they |
---|
992 | will remain joined with that thread. Any subsequent calls to |
---|
993 | @code{pthread_join} on the specified thread will fail. |
---|
994 | |
---|
995 | If value_ptr is NULL, then no value is returned. |
---|
996 | |
---|
997 | @page |
---|
998 | @subsection pthread_self - Get Thread ID |
---|
999 | |
---|
1000 | @subheading CALLING SEQUENCE: |
---|
1001 | |
---|
1002 | @example |
---|
1003 | #include <pthread.h> |
---|
1004 | |
---|
1005 | pthread_t pthread_self( void ); |
---|
1006 | @end example |
---|
1007 | |
---|
1008 | @subheading STATUS CODES: |
---|
1009 | |
---|
1010 | The value returned is the ID of the calling thread. |
---|
1011 | |
---|
1012 | @subheading DESCRIPTION: |
---|
1013 | |
---|
1014 | This routine returns the ID of the calling thread. |
---|
1015 | |
---|
1016 | @subheading NOTES: |
---|
1017 | |
---|
1018 | NONE |
---|
1019 | |
---|
1020 | @page |
---|
1021 | @subsection pthread_equal - Compare Thread IDs |
---|
1022 | |
---|
1023 | @subheading CALLING SEQUENCE: |
---|
1024 | |
---|
1025 | @example |
---|
1026 | #include <pthread.h> |
---|
1027 | |
---|
1028 | int pthread_equal( |
---|
1029 | pthread_t t1, |
---|
1030 | pthread_t t2 |
---|
1031 | ); |
---|
1032 | @end example |
---|
1033 | |
---|
1034 | @subheading STATUS CODES: |
---|
1035 | |
---|
1036 | @table @b |
---|
1037 | @item zero |
---|
1038 | The thread ids are not equal. |
---|
1039 | |
---|
1040 | @item non-zero |
---|
1041 | The thread ids are equal. |
---|
1042 | |
---|
1043 | @end table |
---|
1044 | |
---|
1045 | @subheading DESCRIPTION: |
---|
1046 | |
---|
1047 | The @code{pthread_equal} routine is used to compare two thread |
---|
1048 | IDs and determine if they are equal. |
---|
1049 | |
---|
1050 | @subheading NOTES: |
---|
1051 | |
---|
1052 | The behavior is undefined if the thread IDs are not valid. |
---|
1053 | |
---|
1054 | @page |
---|
1055 | @subsection pthread_once - Dynamic Package Initialization |
---|
1056 | |
---|
1057 | @subheading CALLING SEQUENCE: |
---|
1058 | |
---|
1059 | @example |
---|
1060 | #include <pthread.h> |
---|
1061 | |
---|
1062 | pthread_once_t once_control = PTHREAD_ONCE_INIT; |
---|
1063 | |
---|
1064 | int pthread_once( |
---|
1065 | pthread_once_t *once_control, |
---|
1066 | void (*init_routine)(void) |
---|
1067 | ); |
---|
1068 | @end example |
---|
1069 | |
---|
1070 | @subheading STATUS CODES: |
---|
1071 | |
---|
1072 | NONE |
---|
1073 | |
---|
1074 | @subheading DESCRIPTION: |
---|
1075 | |
---|
1076 | The @code{pthread_once} routine is used to provide controlled initialization |
---|
1077 | of variables. The first call to @code{pthread_once} by any thread with the |
---|
1078 | same @code{once_control} will result in the @code{init_routine} being |
---|
1079 | invoked with no arguments. Subsequent calls to @code{pthread_once} with |
---|
1080 | the same @code{once_control} will have no effect. |
---|
1081 | |
---|
1082 | The @code{init_routine} is guaranteed to have run to completion when |
---|
1083 | this routine returns to the caller. |
---|
1084 | |
---|
1085 | @subheading NOTES: |
---|
1086 | |
---|
1087 | The behavior of @code{pthread_once} is undefined if @code{once_control} |
---|
1088 | is automatic storage (i.e. on a task stack) or is not initialized using |
---|
1089 | @code{PTHREAD_ONCE_INIT}. |
---|
1090 | |
---|
1091 | @page |
---|
1092 | @subsection pthread_setschedparam - Set Thread Scheduling Parameters |
---|
1093 | |
---|
1094 | @subheading CALLING SEQUENCE: |
---|
1095 | |
---|
1096 | @example |
---|
1097 | #include <pthread.h> |
---|
1098 | |
---|
1099 | int pthread_setschedparam( |
---|
1100 | pthread_t thread, |
---|
1101 | int policy, |
---|
1102 | struct sched_param *param |
---|
1103 | ); |
---|
1104 | @end example |
---|
1105 | |
---|
1106 | @subheading STATUS CODES: |
---|
1107 | |
---|
1108 | @table @b |
---|
1109 | @item EINVAL |
---|
1110 | The scheduling parameters indicated by the parameter param is invalid. |
---|
1111 | |
---|
1112 | @item EINVAL |
---|
1113 | The value specified by policy is invalid. |
---|
1114 | |
---|
1115 | @item EINVAL |
---|
1116 | The scheduling policy was SCHED_SPORADIC and the specified replenishment |
---|
1117 | period is less than the initial budget. |
---|
1118 | |
---|
1119 | @item EINVAL |
---|
1120 | The scheduling policy was SCHED_SPORADIC and the specified low priority |
---|
1121 | is invalid. |
---|
1122 | |
---|
1123 | @item ESRCH |
---|
1124 | The thread indicated was invalid. |
---|
1125 | |
---|
1126 | @end table |
---|
1127 | |
---|
1128 | @subheading DESCRIPTION: |
---|
1129 | |
---|
1130 | The @code{pthread_setschedparam} routine is used to set the |
---|
1131 | scheduler parameters currently associated with the thread specified |
---|
1132 | by @code{thread} to the policy specified by @code{policy}. The |
---|
1133 | contents of @code{param} are interpreted based upon the @code{policy} |
---|
1134 | argument. |
---|
1135 | |
---|
1136 | @subheading NOTES: |
---|
1137 | |
---|
1138 | As required by POSIX, RTEMS defines the feature symbol |
---|
1139 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
1140 | family of routines to which this routine belongs is supported. |
---|
1141 | |
---|
1142 | @page |
---|
1143 | @subsection pthread_getschedparam - Get Thread Scheduling Parameters |
---|
1144 | |
---|
1145 | @subheading CALLING SEQUENCE: |
---|
1146 | |
---|
1147 | @example |
---|
1148 | #include <pthread.h> |
---|
1149 | |
---|
1150 | int pthread_getschedparam( |
---|
1151 | pthread_t thread, |
---|
1152 | int *policy, |
---|
1153 | struct sched_param *param |
---|
1154 | ); |
---|
1155 | @end example |
---|
1156 | |
---|
1157 | @subheading STATUS CODES: |
---|
1158 | |
---|
1159 | @table @b |
---|
1160 | @item EINVAL |
---|
1161 | The policy pointer argument is invalid. |
---|
1162 | |
---|
1163 | @item EINVAL |
---|
1164 | The scheduling parameters pointer argument is invalid. |
---|
1165 | |
---|
1166 | @item ESRCH |
---|
1167 | The thread indicated by the parameter thread is invalid. |
---|
1168 | |
---|
1169 | @end table |
---|
1170 | |
---|
1171 | @subheading DESCRIPTION: |
---|
1172 | |
---|
1173 | The @code{pthread_getschedparam} routine is used to obtain the |
---|
1174 | scheduler policy and parameters associated with @code{thread}. |
---|
1175 | The current policy and associated parameters values returned in |
---|
1176 | @code{policy} and @code{param}, respectively. |
---|
1177 | |
---|
1178 | @subheading NOTES: |
---|
1179 | |
---|
1180 | As required by POSIX, RTEMS defines the feature symbol |
---|
1181 | @code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the |
---|
1182 | family of routines to which this routine belongs is supported. |
---|