source: rtems/doc/posix_users/thread.t @ d48ea69

4.104.114.84.95
Last change on this file since d48ea69 was d48ea69, checked in by Joel Sherrill <joel.sherrill@…>, on 06/15/99 at 00:07:14

Significantly enhanced. At least the per routine pages for this chapter
are now filled in.

  • Property mode set to 100644
File size: 28.3 KB
Line 
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
13The thread manager implements the functionality required of the thread
14manager as defined by POSIX 1003.1b-1996.  This standard requires that
15a compliant operating system provide the facilties to manage multiple
16threads of control and defines the API that must be provided.
17
18The 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
52Thread attributes are utilized only at thread creation time.  A thread
53attribute structure may be initialized and passed as an argument to
54the @code{pthread_create} routine.
55
56@table @b
57@item stack address
58is the address of the optionally user specified stack area for this thread.
59If this value is NULL, then RTEMS allocates the memory for the thread stack
60from the RTEMS Workspace Area.  Otherwise, this is the user specified
61address for the memory to be used for the thread's stack.  Each thread must
62have a distinct stack area.  Each processor family has different alignment
63rules which should be followed.
64
65@item stack size
66is the minimum desired size for this thread's stack area.
67If the size of this area as specified by the stack size attribute
68is smaller than the minimum for this processor family and the stack
69is not user specified, then RTEMS will automatically allocate a
70stack of the minimum size for this processor family.
71
72@item contention scope
73specifies the scheduling contention scope.  RTEMS only supports the
74PTHREAD_SCOPE_PROCESS scheduling contention scope.
75
76@item scheduling inheritance
77specifies whether a user specified or the scheduling policy and
78parameters of the currently executing thread are to be used.  When
79this is PTHREAD_INHERIT_SCHED, then the scheduling policy and
80parameters of the currently executing thread are inherited by
81the newly created thread.
82
83@item scheduling policy and parameters
84specify the manner in which the thread will contend for the processor.
85The scheduling parameters are interpreted based on the specified policy.
86All policies utilize the thread priority parameter.
87
88@end table
89
90@section Operations
91
92There is currently no text in this section.
93
94@section Directives
95
96This section details the thread manager's directives.
97A subsection is dedicated to each of this manager's directives
98and describes the calling sequence, related constants, usage,
99and 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
110int pthread_attr_init(
111  pthread_attr_t  *attr
112);
113@end example
114
115@subheading STATUS CODES:
116
117@table @b
118@item EINVAL
119The attribute pointer argument is invalid.
120
121@end table
122
123@subheading DESCRIPTION:
124
125The @code{pthread_attr_init} routine initializes the thread attributes
126object specified by @code{attr} with the default value for all of the
127individual attributes.
128
129@subheading NOTES:
130
131The settings in the default attributes are implementation defined.  For
132RTEMS, the default attributes are as follows:
133
134@itemize @bullet
135
136@item stackadr
137is not set to indicate that RTEMS is to allocate the stack memory.
138
139@item stacksize
140is set to @code{PTHREAD_MINIMUM_STACK_SIZE}.
141
142@item contentionscope
143is set to @code{PTHREAD_SCOPE_PROCESS}.
144
145@item inheritsched
146is set to @code{PTHREAD_INHERIT_SCHED} to indicate that the created
147thread inherits its scheduling attributes from its parent.
148
149@item detachstate
150is 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 
163int pthread_attr_destroy(
164  pthread_attr_t  *attr
165);
166@end example
167
168@subheading STATUS CODES:
169 
170@table @b
171@item EINVAL
172The attribute pointer argument is invalid.
173
174@item EINVAL
175The attribute set is not initialized.
176 
177@end table
178 
179@subheading DESCRIPTION:
180
181The @code{pthread_attr_destroy} routine is used to destroy a thread
182attributes object.  The behavior of using an attributes object after
183it is destroyed is implementation dependent.
184
185@subheading NOTES:
186
187NONE
188
189@page
190@subsection pthread_attr_setdetachstate - Set Detach State
191
192@subheading CALLING SEQUENCE:
193
194@example
195#include <pthread.h>
196 
197int 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
207The attribute pointer argument is invalid.
208
209@item EINVAL
210The attribute set is not initialized.
211 
212@item EINVAL
213The detachstate argument is invalid.
214 
215@end table
216
217@subheading DESCRIPTION:
218
219The @code{pthread_attr_setdetachstate} routine is used to value of the
220@code{detachstate} attribute.  This attribute controls whether the
221thread is created in a detached state. 
222
223The @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
229If a thread is in a detached state,
230then 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 
241int 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
251The attribute pointer argument is invalid.
252
253@item EINVAL
254The attribute set is not initialized.
255 
256@item EINVAL
257The detatchstate pointer argument is invalid.
258
259@end table
260 
261@subheading DESCRIPTION:
262
263The @code{pthread_attr_getdetachstate} routine is used to obtain the
264current value of the @code{detachstate} attribute as specified
265by the @code{attr} thread attribute object.
266
267@subheading NOTES:
268
269NONE
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 
279int 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
289The attribute pointer argument is invalid.
290
291@item EINVAL
292The attribute set is not initialized.
293 
294@end table
295 
296@subheading DESCRIPTION:
297
298The @code{pthread_attr_setstacksize} routine is used to set the
299@code{stacksize} attribute in the @code{attr} thread attribute
300object.
301
302@subheading NOTES:
303
304As required by POSIX, RTEMS defines the feature symbol
305@code{_POSIX_THREAD_ATTR_STACKSIZE} to indicate that this
306routine is supported.
307
308If 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
310for 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
320int 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
330The attribute pointer argument is invalid.
331
332@item EINVAL
333The attribute set is not initialized.
334 
335@item EINVAL
336The stacksize pointer argument is invalid.
337
338@end table
339 
340@subheading DESCRIPTION:
341
342The @code{pthread_attr_getstacksize} routine is used to obtain the
343@code{stacksize} attribute in the @code{attr} thread attribute
344object.
345
346@subheading NOTES:
347
348As required by POSIX, RTEMS defines the feature symbol
349@code{_POSIX_THREAD_ATTR_STACKSIZE} to indicate that this
350routine 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 
360int 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
370The attribute pointer argument is invalid.
371
372@item EINVAL
373The attribute set is not initialized.
374
375@end table
376 
377@subheading DESCRIPTION:
378
379The @code{pthread_attr_setstackaddr} routine is used to set the
380@code{stackaddr} attribute in the @code{attr} thread attribute
381object.
382
383@subheading NOTES:
384
385As required by POSIX, RTEMS defines the feature symbol
386@code{_POSIX_THREAD_ATTR_STACKADDR} to indicate that this
387routine is supported.
388
389It is imperative to the proper operation of the system that
390each 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
400int 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
410The attribute pointer argument is invalid.
411
412@item EINVAL
413The attribute set is not initialized.
414 
415@item EINVAL
416The stackaddr pointer argument is invalid.
417
418@end table
419 
420@subheading DESCRIPTION:
421
422The @code{pthread_attr_getstackaddr} routine is used to obtain the
423@code{stackaddr} attribute in the @code{attr} thread attribute
424object.
425
426@subheading NOTES:
427
428As required by POSIX, RTEMS defines the feature symbol
429@code{_POSIX_THREAD_ATTR_STACKADDR} to indicate that this
430routine 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
440int 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
450The attribute pointer argument is invalid.
451
452@item EINVAL
453The attribute set is not initialized.
454
455@item EINVAL
456The contention scope specified is not valid.
457
458@item ENOTSUP
459The contention scope specified (PTHREAD_SCOPE_SYSTEM) is not supported.
460
461@end table
462
463@subheading DESCRIPTION:
464
465The @code{pthread_attr_setscope} routine is used to set the contention
466scope field in the thread attribute object @code{attr} to the value
467specified by @code{contentionscope}.
468
469The @code{contentionscope} must be either @code{PTHREAD_SCOPE_SYSTEM}
470to indicate that the thread is to be within system scheduling contention
471or @code{PTHREAD_SCOPE_PROCESS} indicating that the thread is to be
472within the process scheduling contention scope.
473
474@subheading NOTES:
475
476As required by POSIX, RTEMS defines the feature symbol
477@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
478family 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
488int 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
498The attribute pointer argument is invalid.
499
500@item EINVAL
501The attribute set is not initialized.
502
503@item EINVAL
504The contentionscope pointer argument is invalid.
505
506@end table
507
508@subheading DESCRIPTION:
509
510The @code{pthread_attr_getscope} routine is used to obtain the
511value of the contention scope field in the thread attributes
512object @code{attr}.  The current value is returned in
513@code{contentionscope}.
514
515@subheading NOTES:
516
517As required by POSIX, RTEMS defines the feature symbol
518@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
519family 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
528int 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
538The attribute pointer argument is invalid.
539
540@item EINVAL
541The attribute set is not initialized.
542
543@item EINVAL
544The specified scheduler inheritance argument is invalid.
545
546@end table
547
548@subheading DESCRIPTION:
549
550The @code{pthread_attr_setinheritsched} routine is used to set the
551inherit scheduler field in the thread attribute object @code{attr} to
552the value specified by @code{inheritsched}. 
553
554The @code{contentionscope} must be either @code{PTHREAD_INHERIT_SCHED}
555to indicate that the thread is to inherit the scheduling policy
556and parameters fromthe creating thread, or @code{PTHREAD_EXPLICIT_SCHED}
557to indicate that the scheduling policy and parameters for this thread
558are to be set from the corresponding values in the attributes object.
559If @code{contentionscope} is @code{PTHREAD_INHERIT_SCHED}, then the
560scheduling attributes in the @code{attr} structure will be ignored
561at thread creation time.
562
563@subheading NOTES:
564
565As required by POSIX, RTEMS defines the feature symbol
566@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
567family 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
577int 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
586The attribute pointer argument is invalid.
587
588@item EINVAL
589The attribute set is not initialized.
590
591@item EINVAL
592The inheritsched pointer argument is invalid.
593
594@end table
595
596@subheading DESCRIPTION:
597
598The @code{pthread_attr_getinheritsched} routine is used to
599object the current value of the inherit scheduler field in
600the thread attribute object @code{attr}.
601
602@subheading NOTES:
603
604As required by POSIX, RTEMS defines the feature symbol
605@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
606family 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
616int 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
625The attribute pointer argument is invalid.
626
627@item EINVAL
628The attribute set is not initialized.
629 
630@item ENOTSUP
631The specified scheduler policy argument is invalid.
632
633@end table
634
635@subheading DESCRIPTION:
636
637The @code{pthread_attr_setschedpolicy} routine is used to set the
638scheduler policy field in the thread attribute object @code{attr} to
639the value specified by @code{policy}.
640
641Scheduling 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
653The precise meaning of each of these is discussed elsewhere in this
654manual.
655
656@subheading NOTES:
657
658As required by POSIX, RTEMS defines the feature symbol
659@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
660family 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
670int 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
679The attribute pointer argument is invalid.
680
681@item EINVAL
682The attribute set is not initialized.
683
684@item EINVAL
685The specified scheduler policy argument pointer is invalid.
686
687@end table
688
689@subheading DESCRIPTION:
690
691The @code{pthread_attr_getschedpolicy} routine is used to obtain the
692scheduler policy field from the thread attribute object @code{attr}.
693The value of this field is returned in @code{policy}.
694
695@subheading NOTES:
696
697As required by POSIX, RTEMS defines the feature symbol
698@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
699family 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
709int 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
718The attribute pointer argument is invalid.
719
720@item EINVAL
721The attribute set is not initialized.
722 
723@item EINVAL
724The specified scheduler parameter argument is invalid.
725
726@end table
727
728@subheading DESCRIPTION:
729
730The @code{pthread_attr_setschedparam} routine is used to set the
731scheduler parameters field in the thread attribute object @code{attr} to
732the value specified by @code{param}.
733
734@subheading NOTES:
735
736As required by POSIX, RTEMS defines the feature symbol
737@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
738family 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
748int 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
757The attribute pointer argument is invalid.
758
759@item EINVAL
760The attribute set is not initialized.
761
762@item EINVAL
763The specified scheduler parameter argument pointer is invalid.
764
765@end table
766
767@subheading DESCRIPTION:
768
769The @code{pthread_attr_getschedparam} routine is used to obtain the
770scheduler parameters field from the thread attribute object @code{attr}.
771The value of this field is returned in @code{param}.
772
773@subheading NOTES:
774
775As required by POSIX, RTEMS defines the feature symbol
776@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
777family 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
787int 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
800The attribute set is not initialized.
801
802@item EINVAL
803The user specified a stack address and the size of the area was not
804large enough to meet this processor's minimum stack requirements.
805
806@item EINVAL
807The specified scheduler inheritance policy was invalid.
808
809@item ENOTSUP
810The specified contention scope was PTHREAD_SCOPE_PROCESS.
811
812@item EINVAL
813The specified thread priority was invalid.
814
815@item EINVAL
816The specified scheduling policy was invalid.
817
818@item EINVAL
819The scheduling policy was SCHED_SPORADIC and the specified replenishment
820period is less than the initial budget.
821
822@item EINVAL
823The scheduling policy was SCHED_SPORADIC and the specified low priority
824is invalid.
825
826@item EAGAIN
827The system lacked the necessary resources to create another thread, or the
828self imposed limit on the total number of threads in a process
829PTHREAD_THREAD_MAX would be exceeded.
830 
831@item EINVAL
832Invalid argument passed.
833
834@end table
835 
836@subheading DESCRIPTION:
837
838The @code{pthread_create} routine is used to create a new thread with
839the attributes specified by @code{attr}.  If the @code{attr} argument
840is @code{NULL}, then the default attribute set will be used.  Modification
841of the contents of @code{attr} after this thread is created does not
842have an impact on this thread. 
843
844The thread begins execution at the address specified by @code{start_routine}
845with @code{arg} as its only argument.  If @code{start_routine} returns,
846then it is functionally equivalent to the thread executing the
847@code{pthread_exit} service.
848
849Upon successful completion, the ID of the created thread is returned in the
850@code{thread} argument.
851
852@subheading NOTES:
853
854There is no concept of a single main thread in RTEMS as there is in
855a tradition UNIX system.  POSIX requires that the implicit return of
856the main thread results in the same effects as if there were a call
857to @code{exit}.  This does not occur in RTEMS.
858
859The signal mask of the newly created thread is inherited from its
860creator 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
870void 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
883The @code{pthread_exit} routine is used to temrinate the calling thread.
884The @code{status} is made available to any successful join with the
885terminating thread.
886
887When a thread returns from its start routine, it results in an
888implicit call to the @code{pthread_exit} routine with the return
889value of the function serving as the argument to @code{pthread_exit}.
890
891@subheading NOTES:
892
893Any cancellation cleanup handlers that hace been pushed and not yet popped
894shall be popped in reverse of the order that they were pushed.  After
895all cancellation cleanup handlers have been executed, if the
896thread has any thread-specific data, destructors for that data will
897be invoked.
898
899Thread termination does not release or free any application visible
900resources including byt not limited to mutexes, file descriptors, allocated
901memory, etc..  Similarly, exitting a thread does not result in any
902process-oriented cleanup activity.
903
904There is no concept of a single main thread in RTEMS as there is in
905a tradition UNIX system.  POSIX requires that the implicit return of
906the main thread results in the same effects as if there were a call
907to @code{exit}.  This does not occur in RTEMS.
908
909All access to any automatic variables allocated by the threads is lost
910when the thread exits.  Thus references (i.e. pointers) to local variables
911of a thread should not be used in a global manner without care.  As
912a specific example, a pointer to a local variable should NOT be used
913as 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
924int pthread_detach(
925  pthread_t   thread
926);
927@end example
928
929@subheading STATUS CODES:
930@table @b
931@item ESRCH
932The thread specified is invalid.
933 
934@item EINVAL
935The thread specified is not a joinable thread.
936 
937@end table
938
939@subheading DESCRIPTION:
940
941The @code{pthread_detach} routine is used to to indicate that storage
942for @code{thread} can be reclaimed when the thread terminates without
943another thread joinging with it.
944
945@subheading NOTES:
946
947If any threads have previously joined with the specified thread, then they
948will 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
959int 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
968The thread specified is invalid.
969 
970@item EINVAL
971The thread specified is not a joinable thread.
972 
973@item EDEADLK
974A deadlock was detected or thread is the calling thread.
975 
976@end table
977
978@subheading DESCRIPTION:
979
980The @code{pthread_join} routine suspends execution of the calling thread
981until @code{thread} terminates.  If @code{thread} has already terminated,
982then 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
985When this routine returns, then @code{thread} has been temrinated. 
986
987@subheading NOTES:
988
989The results of multiple simultaneous joins on the same thread is undefined.
990
991If any threads have previously joined with the specified thread, then they
992will remain joined with that thread.  Any subsequent calls to
993@code{pthread_join} on the specified thread will fail.
994
995If 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
1005pthread_t pthread_self( void );
1006@end example
1007
1008@subheading STATUS CODES:
1009
1010The value returned is the ID of the calling thread.
1011
1012@subheading DESCRIPTION:
1013
1014This routine returns the ID of the calling thread.
1015
1016@subheading NOTES:
1017
1018NONE
1019
1020@page
1021@subsection pthread_equal - Compare Thread IDs
1022
1023@subheading CALLING SEQUENCE:
1024
1025@example
1026#include <pthread.h>
1027
1028int 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
1038The thread ids are not equal.
1039 
1040@item non-zero
1041The thread ids are equal.
1042 
1043@end table
1044
1045@subheading DESCRIPTION:
1046
1047The @code{pthread_equal} routine is used to compare two thread
1048IDs and determine if they are equal.
1049
1050@subheading NOTES:
1051
1052The 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
1062pthread_once_t once_control = PTHREAD_ONCE_INIT;
1063
1064int pthread_once(
1065  pthread_once_t  *once_control,
1066  void           (*init_routine)(void)
1067);
1068@end example
1069
1070@subheading STATUS CODES:
1071
1072NONE
1073
1074@subheading DESCRIPTION:
1075
1076The @code{pthread_once} routine is used to provide controlled initialization
1077of variables.  The first call to @code{pthread_once} by any thread with the
1078same @code{once_control} will result in the @code{init_routine} being
1079invoked with no arguments.  Subsequent calls to @code{pthread_once} with
1080the same @code{once_control} will have no effect. 
1081
1082The @code{init_routine} is guaranteed to have run to completion when
1083this routine returns to the caller.
1084
1085@subheading NOTES:
1086
1087The behavior of @code{pthread_once} is undefined if @code{once_control}
1088is 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
1099int 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
1110The scheduling parameters indicated by the parameter param is invalid.
1111
1112@item EINVAL
1113The value specified by policy is invalid.
1114
1115@item EINVAL
1116The scheduling policy was SCHED_SPORADIC and the specified replenishment
1117period is less than the initial budget.
1118
1119@item EINVAL
1120The scheduling policy was SCHED_SPORADIC and the specified low priority
1121is invalid.
1122
1123@item ESRCH
1124The thread indicated was invalid.
1125
1126@end table
1127
1128@subheading DESCRIPTION:
1129
1130The @code{pthread_setschedparam} routine is used to set the
1131scheduler parameters currently associated with the thread specified
1132by @code{thread} to the policy specified by @code{policy}.  The
1133contents of @code{param} are interpreted based upon the @code{policy}
1134argument.
1135
1136@subheading NOTES:
1137
1138As required by POSIX, RTEMS defines the feature symbol
1139@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
1140family 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
1150int 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
1161The policy pointer argument is invalid.
1162
1163@item EINVAL
1164The scheduling parameters pointer argument is invalid.
1165
1166@item ESRCH
1167The thread indicated by the parameter thread is invalid.
1168 
1169@end table
1170
1171@subheading DESCRIPTION:
1172
1173The @code{pthread_getschedparam} routine is used to obtain the
1174scheduler policy and parameters associated with @code{thread}.
1175The current policy and associated parameters values returned in
1176@code{policy} and @code{param}, respectively.
1177
1178@subheading NOTES:
1179
1180As required by POSIX, RTEMS defines the feature symbol
1181@code{_POSIX_THREAD_PRIORITY_SCHEDULING} to indicate that the
1182family of routines to which this routine belongs is supported.
Note: See TracBrowser for help on using the repository browser.