source: rtems-docs/posix-users/thread.rst @ 969e60e

5
Last change on this file since 969e60e was d36d685, checked in by Joel Sherrill <joel@…>, on 10/12/17 at 00:56:20

posix-users/thread.rst: Add pthread_getconcurrency and pthread_setconcurrency

Closes #2680.

  • Property mode set to 100644
File size: 37.7 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2002.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Thread Manager
8##############
9
10Introduction
11============
12
13The thread manager implements the functionality required of the thread manager
14as defined by POSIX 1003.1b. This standard requires that a compliant operating
15system provide the facilties to manage multiple threads of control and defines
16the API that must be provided.
17
18The services provided by the thread manager are:
19
20- pthread_attr_init_ - Initialize a Thread Attribute Set
21
22- pthread_attr_destroy_ - Destroy a Thread Attribute Set
23
24- pthread_attr_setdetachstate_ - Set Detach State
25
26- pthread_attr_getdetachstate_ - Get Detach State
27
28- pthread_attr_setstacksize_ - Set Thread Stack Size
29
30- pthread_attr_getstacksize_ - Get Thread Stack Size
31
32- pthread_attr_setstackaddr_ - Set Thread Stack Address
33
34- pthread_attr_getstackaddr_ - Get Thread Stack Address
35
36- pthread_attr_setscope_ - Set Thread Scheduling Scope
37
38- pthread_attr_getscope_ - Get Thread Scheduling Scope
39
40- pthread_attr_setinheritsched_ - Set Inherit Scheduler Flag
41
42- pthread_attr_getinheritsched_ - Get Inherit Scheduler Flag
43
44- pthread_attr_setschedpolicy_ - Set Scheduling Policy
45
46- pthread_attr_getschedpolicy_ - Get Scheduling Policy
47
48- pthread_attr_setschedparam_ - Set Scheduling Parameters
49
50- pthread_attr_getschedparam_ - Get Scheduling Parameters
51
52- pthread_attr_getaffinity_np_ - Get Thread Affinity Attribute
53
54- pthread_attr_setaffinity_np_ - Set Thread Affinity Attribute
55
56- pthread_create_ - Create a Thread
57
58- pthread_exit_ - Terminate the Current Thread
59
60- pthread_detach_ - Detach a Thread
61
62- pthread_getconcurrency_ - Get Thread Level of Concurrency
63
64- pthread_setconcurrency_ - Set Thread Level of Concurrency
65
66- pthread_getattr_np_ - Get Thread Attributes
67
68- pthread_join_ - Wait for Thread Termination
69
70- pthread_self_ - Get Thread ID
71
72- pthread_equal_ - Compare Thread IDs
73
74- pthread_once_ - Dynamic Package Initialization
75
76- pthread_setschedparam_ - Set Thread Scheduling Parameters
77
78- pthread_getschedparam_ - Get Thread Scheduling Parameters
79
80- pthread_getaffinity_np_ - Get Thread Affinity
81
82- pthread_setaffinity_np_ - Set Thread Affinity
83
84Background
85==========
86
87Thread Attributes
88-----------------
89
90Thread attributes are utilized only at thread creation time. A thread attribute
91structure may be initialized and passed as an argument to the
92``pthread_create`` routine.
93
94*stack address*
95    is the address of the optionally user specified stack area for this thread.
96    If this value is NULL, then RTEMS allocates the memory for the thread stack
97    from the RTEMS Workspace Area. Otherwise, this is the user specified
98    address for the memory to be used for the thread's stack. Each thread must
99    have a distinct stack area. Each processor family has different alignment
100    rules which should be followed.
101
102*stack size*
103    is the minimum desired size for this thread's stack area.  If the size of
104    this area as specified by the stack size attribute is smaller than the
105    minimum for this processor family and the stack is not user specified, then
106    RTEMS will automatically allocate a stack of the minimum size for this
107    processor family.
108
109*contention scope*
110    specifies the scheduling contention scope. RTEMS only supports the
111    PTHREAD_SCOPE_PROCESS scheduling contention scope.
112
113*scheduling inheritance*
114    specifies whether a user specified or the scheduling policy and parameters
115    of the currently executing thread are to be used. When this is
116    PTHREAD_INHERIT_SCHED, then the scheduling policy and parameters of the
117    currently executing thread are inherited by the newly created thread.
118
119*scheduling policy and parameters*
120    specify the manner in which the thread will contend for the processor.  The
121    scheduling parameters are interpreted based on the specified policy.  All
122    policies utilize the thread priority parameter.
123
124Operations
125==========
126
127There is currently no text in this section.
128
129Services
130========
131
132This section details the thread manager's services.  A subsection is dedicated
133to each of this manager's services and describes the calling sequence, related
134constants, usage, and status codes.
135
136.. _pthread_attr_init:
137
138pthread_attr_init - Initialize a Thread Attribute Set
139-----------------------------------------------------
140.. index:: pthread_attr_init
141.. index:: initialize a thread attribute set
142
143**CALLING SEQUENCE:**
144
145.. code-block:: c
146
147    #include <pthread.h>
148    int pthread_attr_init(
149        pthread_attr_t *attr
150    );
151
152**STATUS CODES:**
153
154.. list-table::
155 :class: rtems-table
156
157 * - ``EINVAL``
158   - The attribute pointer argument is invalid.
159
160**DESCRIPTION:**
161
162The ``pthread_attr_init`` routine initializes the thread attributes object
163specified by ``attr`` with the default value for all of the individual
164attributes.
165
166**NOTES:**
167
168The settings in the default attributes are implementation defined. For RTEMS,
169the default attributes are as follows:
170
171.. list-table::
172 :class: rtems-table
173
174 * - *stackadr*
175   - is not set to indicate that RTEMS is to allocate the stack memory.
176 * - *stacksize*
177   - is set to ``PTHREAD_MINIMUM_STACK_SIZE``.
178 * - *contentionscope*
179   - is set to ``PTHREAD_SCOPE_PROCESS``.
180 * - *inheritsched*
181   - is set to ``PTHREAD_INHERIT_SCHED`` to indicate that the created thread
182     inherits its scheduling attributes from its parent.
183 * - detachstate
184   - is set to ``PTHREAD_CREATE_JOINABLE``.
185
186.. _pthread_attr_destroy:
187
188pthread_attr_destroy - Destroy a Thread Attribute Set
189-----------------------------------------------------
190.. index:: pthread_attr_destroy
191.. index:: destroy a thread attribute set
192
193**CALLING SEQUENCE:**
194
195.. code-block:: c
196
197    #include <pthread.h>
198    int pthread_attr_destroy(
199        pthread_attr_t *attr
200    );
201
202**STATUS CODES:**
203
204.. list-table::
205 :class: rtems-table
206
207 * - ``EINVAL``
208   - The attribute pointer argument is invalid.
209 * - ``EINVAL``
210   - The attribute set is not initialized.
211
212**DESCRIPTION:**
213
214The ``pthread_attr_destroy`` routine is used to destroy a thread attributes
215object. The behavior of using an attributes object after it is destroyed is
216implementation dependent.
217
218**NOTES:**
219
220NONE
221
222.. _pthread_attr_setdetachstate:
223
224pthread_attr_setdetachstate - Set Detach State
225----------------------------------------------
226.. index:: pthread_attr_setdetachstate
227.. index:: set detach state
228
229**CALLING SEQUENCE:**
230
231.. code-block:: c
232
233    #include <pthread.h>
234    int pthread_attr_setdetachstate(
235        pthread_attr_t *attr,
236        int             detachstate
237    );
238
239**STATUS CODES:**
240
241.. list-table::
242 :class: rtems-table
243
244 * - ``EINVAL``
245   - The attribute pointer argument is invalid.
246 * - ``EINVAL``
247   - The attribute set is not initialized.
248 * - ``EINVAL``
249   - The detachstate argument is invalid.
250
251**DESCRIPTION:**
252
253The ``pthread_attr_setdetachstate`` routine is used to value of the
254``detachstate`` attribute. This attribute controls whether the thread is
255created in a detached state.
256
257The ``detachstate`` can be either ``PTHREAD_CREATE_DETACHED`` or
258``PTHREAD_CREATE_JOINABLE``. The default value for all threads is
259``PTHREAD_CREATE_JOINABLE``.
260
261**NOTES:**
262
263If a thread is in a detached state, then the use of the ID with the
264``pthread_detach`` or ``pthread_join`` routines is an error.
265
266.. _pthread_attr_getdetachstate:
267
268pthread_attr_getdetachstate - Get Detach State
269----------------------------------------------
270.. index:: pthread_attr_getdetachstate
271.. index:: get detach state
272
273**CALLING SEQUENCE:**
274
275.. code-block:: c
276
277    #include <pthread.h>
278    int pthread_attr_getdetachstate(
279        const pthread_attr_t *attr,
280        int                  *detachstate
281    );
282
283**STATUS CODES:**
284
285.. list-table::
286 :class: rtems-table
287
288 * - ``EINVAL``
289   - The attribute pointer argument is invalid.
290 * - ``EINVAL``
291   - The attribute set is not initialized.
292 * - ``EINVAL``
293   - The detatchstate pointer argument is invalid.
294
295**DESCRIPTION:**
296
297The ``pthread_attr_getdetachstate`` routine is used to obtain the current value
298of the ``detachstate`` attribute as specified by the ``attr`` thread attribute
299object.
300
301**NOTES:**
302
303NONE
304
305.. _pthread_attr_setstacksize:
306
307pthread_attr_setstacksize - Set Thread Stack Size
308-------------------------------------------------
309.. index:: pthread_attr_setstacksize
310.. index:: set thread stack size
311
312**CALLING SEQUENCE:**
313
314.. code-block:: c
315
316    #include <pthread.h>
317    int pthread_attr_setstacksize(
318        pthread_attr_t *attr,
319        size_t          stacksize
320    );
321
322**STATUS CODES:**
323
324.. list-table::
325 :class: rtems-table
326
327 * - ``EINVAL``
328   - The attribute pointer argument is invalid.
329 * - ``EINVAL``
330   - The attribute set is not initialized.
331
332**DESCRIPTION:**
333
334The ``pthread_attr_setstacksize`` routine is used to set the ``stacksize``
335attribute in the ``attr`` thread attribute object.
336
337**NOTES:**
338
339As required by POSIX, RTEMS defines the feature symbol
340``_POSIX_THREAD_ATTR_STACKSIZE`` to indicate that this routine is supported.
341
342If the specified stacksize is below the minimum required for this CPU
343(``PTHREAD_STACK_MIN``, then the stacksize will be set to the minimum for this
344CPU.
345
346.. _pthread_attr_getstacksize:
347
348pthread_attr_getstacksize - Get Thread Stack Size
349-------------------------------------------------
350.. index:: pthread_attr_getstacksize
351.. index:: get thread stack size
352
353**CALLING SEQUENCE:**
354
355.. code-block:: c
356
357    #include <pthread.h>
358    int pthread_attr_getstacksize(
359        const pthread_attr_t *attr,
360        size_t               *stacksize
361    );
362
363**STATUS CODES:**
364
365.. list-table::
366 :class: rtems-table
367
368 * - ``EINVAL``
369   - The attribute pointer argument is invalid.
370 * - ``EINVAL``
371   - The attribute set is not initialized.
372 * - ``EINVAL``
373   - The stacksize pointer argument is invalid.
374
375**DESCRIPTION:**
376
377The ``pthread_attr_getstacksize`` routine is used to obtain the ``stacksize``
378attribute in the ``attr`` thread attribute object.
379
380**NOTES:**
381
382As required by POSIX, RTEMS defines the feature symbol
383``_POSIX_THREAD_ATTR_STACKSIZE`` to indicate that this routine is supported.
384
385.. _pthread_attr_setstackaddr:
386
387pthread_attr_setstackaddr - Set Thread Stack Address
388----------------------------------------------------
389.. index:: pthread_attr_setstackaddr
390.. index:: set thread stack address
391
392**CALLING SEQUENCE:**
393
394.. code-block:: c
395
396    #include <pthread.h>
397    int pthread_attr_setstackaddr(
398        pthread_attr_t *attr,
399        void           *stackaddr
400    );
401
402**STATUS CODES:**
403
404.. list-table::
405 :class: rtems-table
406
407 * - ``EINVAL``
408   - The attribute pointer argument is invalid.
409 * - ``EINVAL``
410   - The attribute set is not initialized.
411
412**DESCRIPTION:**
413
414The ``pthread_attr_setstackaddr`` routine is used to set the ``stackaddr``
415attribute in the ``attr`` thread attribute object.
416
417**NOTES:**
418
419As required by POSIX, RTEMS defines the feature symbol
420``_POSIX_THREAD_ATTR_STACKADDR`` to indicate that this routine is supported.
421
422It is imperative to the proper operation of the system that each thread have
423sufficient stack space.
424
425.. _pthread_attr_getstackaddr:
426
427pthread_attr_getstackaddr - Get Thread Stack Address
428----------------------------------------------------
429.. index:: pthread_attr_getstackaddr
430.. index:: get thread stack address
431
432**CALLING SEQUENCE:**
433
434.. code-block:: c
435
436    #include <pthread.h>
437    int pthread_attr_getstackaddr(
438        const pthread_attr_t  *attr,
439        void                 **stackaddr
440    );
441
442**STATUS CODES:**
443
444.. list-table::
445 :class: rtems-table
446
447 * - ``EINVAL``
448   - The attribute pointer argument is invalid.
449 * - ``EINVAL``
450   - The attribute set is not initialized.
451 * - ``EINVAL``
452   - The stackaddr pointer argument is invalid.
453
454**DESCRIPTION:**
455
456The ``pthread_attr_getstackaddr`` routine is used to obtain the ``stackaddr``
457attribute in the ``attr`` thread attribute object.
458
459**NOTES:**
460
461As required by POSIX, RTEMS defines the feature symbol
462``_POSIX_THREAD_ATTR_STACKADDR`` to indicate that this routine is supported.
463
464.. _pthread_attr_setscope:
465
466pthread_attr_setscope - Set Thread Scheduling Scope
467---------------------------------------------------
468.. index:: pthread_attr_setscope
469.. index:: set thread scheduling scope
470
471**CALLING SEQUENCE:**
472
473.. code-block:: c
474
475    #include <pthread.h>
476    int pthread_attr_setscope(
477        pthread_attr_t *attr,
478        int             contentionscope
479    );
480
481**STATUS CODES:**
482
483.. list-table::
484 :class: rtems-table
485
486 * - ``EINVAL``
487   - The attribute pointer argument is invalid.
488 * - ``EINVAL``
489   - The attribute set is not initialized.
490 * - ``EINVAL``
491   - The contention scope specified is not valid.
492 * - ``ENOTSUP``
493   - The contention scope specified (``PTHREAD_SCOPE_SYSTEM``) is not supported.
494
495**DESCRIPTION:**
496
497The ``pthread_attr_setscope`` routine is used to set the contention scope field
498in the thread attribute object ``attr`` to the value specified by
499``contentionscope``.
500
501The ``contentionscope`` must be either ``PTHREAD_SCOPE_SYSTEM`` to indicate
502that the thread is to be within system scheduling contention or
503``PTHREAD_SCOPE_PROCESS`` indicating that the thread is to be within the
504process scheduling contention scope.
505
506**NOTES:**
507
508As required by POSIX, RTEMS defines the feature symbol
509``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
510to which this routine belongs is supported.
511
512.. _pthread_attr_getscope:
513
514pthread_attr_getscope - Get Thread Scheduling Scope
515---------------------------------------------------
516.. index:: pthread_attr_getscope
517.. index:: get thread scheduling scope
518
519**CALLING SEQUENCE:**
520
521.. code-block:: c
522
523    #include <pthread.h>
524    int pthread_attr_getscope(
525        const pthread_attr_t *attr,
526        int                  *contentionscope
527    );
528
529**STATUS CODES:**
530
531.. list-table::
532 :class: rtems-table
533
534 * - ``EINVAL``
535   - The attribute pointer argument is invalid.
536 * - ``EINVAL``
537   - The attribute set is not initialized.
538 * - ``EINVAL``
539   - The contentionscope pointer argument is invalid.
540
541**DESCRIPTION:**
542
543The ``pthread_attr_getscope`` routine is used to obtain the value of the
544contention scope field in the thread attributes object ``attr``. The current
545value is returned in ``contentionscope``.
546
547**NOTES:**
548
549As required by POSIX, RTEMS defines the feature symbol
550``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
551to which this routine belongs is supported.
552
553.. _pthread_attr_setinheritsched:
554
555pthread_attr_setinheritsched - Set Inherit Scheduler Flag
556---------------------------------------------------------
557.. index:: pthread_attr_setinheritsched
558.. index:: set inherit scheduler flag
559
560**CALLING SEQUENCE:**
561
562.. code-block:: c
563
564    #include <pthread.h>
565    int pthread_attr_setinheritsched(
566        pthread_attr_t *attr,
567        int             inheritsched
568    );
569
570**STATUS CODES:**
571
572.. list-table::
573 :class: rtems-table
574
575 * - ``EINVAL``
576   - The attribute pointer argument is invalid.
577 * - ``EINVAL``
578   - The attribute set is not initialized.
579 * - ``EINVAL``
580   - The specified scheduler inheritance argument is invalid.
581
582**DESCRIPTION:**
583
584The ``pthread_attr_setinheritsched`` routine is used to set the inherit
585scheduler field in the thread attribute object ``attr`` to the value specified
586by ``inheritsched``.
587
588The ``contentionscope`` must be either ``PTHREAD_INHERIT_SCHED`` to indicate
589that the thread is to inherit the scheduling policy and parameters fromthe
590creating thread, or ``PTHREAD_EXPLICIT_SCHED`` to indicate that the scheduling
591policy and parameters for this thread are to be set from the corresponding
592values in the attributes object.  If ``contentionscope`` is
593``PTHREAD_INHERIT_SCHED``, then the scheduling attributes in the ``attr``
594structure will be ignored at thread creation time.
595
596**NOTES:**
597
598As required by POSIX, RTEMS defines the feature symbol
599``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
600to which this routine belongs is supported.
601
602.. _pthread_attr_getinheritsched:
603
604pthread_attr_getinheritsched - Get Inherit Scheduler Flag
605---------------------------------------------------------
606.. index:: pthread_attr_getinheritsched
607.. index:: get inherit scheduler flag
608
609**CALLING SEQUENCE:**
610
611.. code-block:: c
612
613    #include <pthread.h>
614    int pthread_attr_getinheritsched(
615        const pthread_attr_t *attr,
616        int                  *inheritsched
617    );
618
619**STATUS CODES:**
620
621.. list-table::
622 :class: rtems-table
623
624 * - ``EINVAL``
625   - The attribute pointer argument is invalid.
626 * - ``EINVAL``
627   - The attribute set is not initialized.
628 * - ``EINVAL``
629   - The inheritsched pointer argument is invalid.
630
631**DESCRIPTION:**
632
633The ``pthread_attr_getinheritsched`` routine is used to object the current
634value of the inherit scheduler field in the thread attribute object ``attr``.
635
636**NOTES:**
637
638As required by POSIX, RTEMS defines the feature symbol
639``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
640to which this routine belongs is supported.
641
642.. _pthread_attr_setschedpolicy:
643
644pthread_attr_setschedpolicy - Set Scheduling Policy
645---------------------------------------------------
646.. index:: pthread_attr_setschedpolicy
647.. index:: set scheduling policy
648
649**CALLING SEQUENCE:**
650
651.. code-block:: c
652
653    #include <pthread.h>
654    int pthread_attr_setschedpolicy(
655        pthread_attr_t *attr,
656        int             policy
657    );
658
659**STATUS CODES:**
660
661.. list-table::
662 :class: rtems-table
663
664 * - ``EINVAL``
665   - The attribute pointer argument is invalid.
666 * - ``EINVAL``
667   - The attribute set is not initialized.
668 * - ``ENOTSUP``
669   - The specified scheduler policy argument is invalid.
670
671**DESCRIPTION:**
672
673The ``pthread_attr_setschedpolicy`` routine is used to set the scheduler policy
674field in the thread attribute object ``attr`` to the value specified by
675``policy``.
676
677Scheduling policies may be one of the following:
678
679- ``SCHED_DEFAULT``
680
681- ``SCHED_FIFO``
682
683- ``SCHED_RR``
684
685- ``SCHED_SPORADIC``
686
687- ``SCHED_OTHER``
688
689The precise meaning of each of these is discussed elsewhere in this manual.
690
691**NOTES:**
692
693As required by POSIX, RTEMS defines the feature symbol
694``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
695to which this routine belongs is supported.
696
697.. _pthread_attr_getschedpolicy:
698
699pthread_attr_getschedpolicy - Get Scheduling Policy
700---------------------------------------------------
701.. index:: pthread_attr_getschedpolicy
702.. index:: get scheduling policy
703
704**CALLING SEQUENCE:**
705
706.. code-block:: c
707
708    #include <pthread.h>
709    int pthread_attr_getschedpolicy(
710        const pthread_attr_t *attr,
711        int                  *policy
712    );
713
714**STATUS CODES:**
715
716.. list-table::
717 :class: rtems-table
718
719 * - ``EINVAL``
720   - The attribute pointer argument is invalid.
721 * - ``EINVAL``
722   - The attribute set is not initialized.
723 * - ``EINVAL``
724   - The specified scheduler policy argument pointer is invalid.
725
726**DESCRIPTION:**
727
728The ``pthread_attr_getschedpolicy`` routine is used to obtain the scheduler
729policy field from the thread attribute object ``attr``.  The value of this
730field is returned in ``policy``.
731
732**NOTES:**
733
734As required by POSIX, RTEMS defines the feature symbol
735``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
736to which this routine belongs is supported.
737
738.. _pthread_attr_setschedparam:
739
740pthread_attr_setschedparam - Set Scheduling Parameters
741------------------------------------------------------
742.. index:: pthread_attr_setschedparam
743.. index:: set scheduling parameters
744
745**CALLING SEQUENCE:**
746
747.. code-block:: c
748
749    #include <pthread.h>
750    int pthread_attr_setschedparam(
751        pthread_attr_t           *attr,
752        const struct sched_param  param
753    );
754
755**STATUS CODES:**
756
757.. list-table::
758 :class: rtems-table
759
760 * - ``EINVAL``
761   - The attribute pointer argument is invalid.
762 * - ``EINVAL``
763   - The attribute set is not initialized.
764 * - ``EINVAL``
765   - The specified scheduler parameter argument is invalid.
766
767**DESCRIPTION:**
768
769The ``pthread_attr_setschedparam`` routine is used to set the scheduler
770parameters field in the thread attribute object ``attr`` to the value specified
771by ``param``.
772
773**NOTES:**
774
775As required by POSIX, RTEMS defines the feature symbol
776``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
777to which this routine belongs is supported.
778
779.. _pthread_attr_getschedparam:
780
781pthread_attr_getschedparam - Get Scheduling Parameters
782------------------------------------------------------
783.. index:: pthread_attr_getschedparam
784.. index:: get scheduling parameters
785
786**CALLING SEQUENCE:**
787
788.. code-block:: c
789
790    #include <pthread.h>
791    int pthread_attr_getschedparam(
792        const pthread_attr_t *attr,
793        struct sched_param   *param
794    );
795
796**STATUS CODES:**
797
798.. list-table::
799 :class: rtems-table
800
801 * - ``EINVAL``
802   - The attribute pointer argument is invalid.
803 * - ``EINVAL``
804   - The attribute set is not initialized.
805 * - ``EINVAL``
806   - The specified scheduler parameter argument pointer is invalid.
807
808**DESCRIPTION:**
809
810The ``pthread_attr_getschedparam`` routine is used to obtain the scheduler
811parameters field from the thread attribute object ``attr``.  The value of this
812field is returned in ``param``.
813
814**NOTES:**
815
816As required by POSIX, RTEMS defines the feature symbol
817``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
818to which this routine belongs is supported.
819
820.. _pthread_attr_getaffinity_np:
821
822pthread_attr_getaffinity_np - Get Thread Affinity Attribute
823-----------------------------------------------------------
824
825**CALLING SEQUENCE:**
826
827.. code-block:: c
828
829    #define _GNU_SOURCE
830    #include <pthread.h>
831    int pthread_attr_getaffinity_np(
832        const pthread_attr_t *attr,
833        size_t                cpusetsize,
834        cpu_set_t            *cpuset
835    );
836
837**STATUS CODES:**
838
839.. list-table::
840 :class: rtems-table
841
842 * - ``EFAULT``
843   - The attribute pointer argument is invalid.
844 * - ``EFAULT``
845   - The cpuset pointer argument is invalid.
846 * - ``EINVAL``
847   - The ``cpusetsize`` does not match the value of ``affinitysetsize`` field
848     in the thread attribute object.
849
850**DESCRIPTION:**
851
852The ``pthread_attr_getaffinity_np`` routine is used to obtain the
853``affinityset`` field from the thread attribute object ``attr``.  The value of
854this field is returned in ``cpuset``.
855
856**NOTES:**
857
858NONE
859
860.. _pthread_attr_setaffinity_np:
861
862pthread_attr_setaffinity_np - Set Thread Affinity Attribute
863-----------------------------------------------------------
864
865**CALLING SEQUENCE:**
866
867.. code-block:: c
868
869    #define _GNU_SOURCE
870    #include <pthread.h>
871    int pthread_attr_setaffinity_np(
872        pthread_attr_t    *attr,
873        size_t             cpusetsize,
874        const cpu_set_t   *cpuset
875    );
876
877**STATUS CODES:**
878
879.. list-table::
880 :class: rtems-table
881
882 * - ``EFAULT``
883   - The attribute pointer argument is invalid.
884 * - ``EFAULT``
885   - The cpuset pointer argument is invalid.
886 * - ``EINVAL``
887   - The ``cpusetsize`` does not match the value of ``affinitysetsize`` field
888     in the thread attribute object.
889 * - ``EINVAL``
890   - The ``cpuset`` did not select a valid cpu.
891 * - ``EINVAL``
892   - The ``cpuset`` selected a cpu that was invalid.
893
894**DESCRIPTION:**
895
896The ``pthread_attr_setaffinity_np`` routine is used to set the ``affinityset``
897field in the thread attribute object ``attr``.  The value of this field is
898returned in ``cpuset``.
899
900**NOTES:**
901
902NONE
903
904.. _pthread_create:
905
906pthread_create - Create a Thread
907--------------------------------
908.. index:: pthread_create
909.. index:: create a thread
910
911**CALLING SEQUENCE:**
912
913.. code-block:: c
914
915    #include <pthread.h>
916    int pthread_create(
917        pthread_t             *thread,
918        const pthread_attr_t  *attr,
919        void                 (*start_routine)( void *),
920        void                  *arg
921    );
922
923**STATUS CODES:**
924
925.. list-table::
926 :class: rtems-table
927
928 * - ``EINVAL``
929   - The attribute set is not initialized.
930 * - ``EINVAL``
931   - The user specified a stack address and the size of the area was not large
932     enough to meet this processor's minimum stack requirements.
933 * - ``EINVAL``
934   - The specified scheduler inheritance policy was invalid.
935 * - ``ENOTSUP``
936   - The specified contention scope was ``PTHREAD_SCOPE_PROCESS``.
937 * - ``EINVAL``
938   - The specified thread priority was invalid.
939 * - ``EINVAL``
940   - The specified scheduling policy was invalid.
941 * - ``EINVAL``
942   - The scheduling policy was ``SCHED_SPORADIC`` and the specified
943     replenishment period is less than the initial budget.
944 * - ``EINVAL``
945   - The scheduling policy was ``SCHED_SPORADIC`` and the specified low
946     priority is invalid.
947 * - ``EAGAIN``
948   - The system lacked the necessary resources to create another thread, or the
949     self imposed limit on the total number of threads in a process
950     ``PTHREAD_THREAD_MAX`` would be exceeded.
951 * - ``EINVAL``
952   - Invalid argument passed.
953
954**DESCRIPTION:**
955
956The ``pthread_create`` routine is used to create a new thread with the
957attributes specified by ``attr``. If the ``attr`` argument is ``NULL``, then
958the default attribute set will be used. Modification of the contents of
959``attr`` after this thread is created does not have an impact on this thread.
960
961The thread begins execution at the address specified by ``start_routine`` with
962``arg`` as its only argument. If ``start_routine`` returns, then it is
963functionally equivalent to the thread executing the ``pthread_exit`` service.
964
965Upon successful completion, the ID of the created thread is returned in the
966``thread`` argument.
967
968**NOTES:**
969
970There is no concept of a single main thread in RTEMS as there is in a tradition
971UNIX system. POSIX requires that the implicit return of the main thread results
972in the same effects as if there were a call to ``exit``. This does not occur in
973RTEMS.
974
975The signal mask of the newly created thread is inherited from its creator and
976the set of pending signals for this thread is empty.
977
978.. _pthread_exit:
979
980pthread_exit - Terminate the Current Thread
981-------------------------------------------
982.. index:: pthread_exit
983.. index:: terminate the current thread
984
985**CALLING SEQUENCE:**
986
987.. code-block:: c
988
989    #include <pthread.h>
990    void pthread_exit(
991        void *status
992    );
993
994**STATUS CODES:**
995
996*NONE*
997
998**DESCRIPTION:**
999
1000The ``pthread_exit`` routine is used to terminate the calling thread.  The
1001``status`` is made available to any successful join with the terminating
1002thread.
1003
1004When a thread returns from its start routine, it results in an implicit call to
1005the ``pthread_exit`` routine with the return value of the function serving as
1006the argument to ``pthread_exit``.
1007
1008**NOTES:**
1009
1010Any cancellation cleanup handlers that hace been pushed and not yet popped
1011shall be popped in reverse of the order that they were pushed. After all
1012cancellation cleanup handlers have been executed, if the thread has any
1013thread-specific data, destructors for that data will be invoked.
1014
1015Thread termination does not release or free any application visible resources
1016including byt not limited to mutexes, file descriptors, allocated memory,
1017etc.. Similarly, exitting a thread does not result in any process-oriented
1018cleanup activity.
1019
1020There is no concept of a single main thread in RTEMS as there is in a tradition
1021UNIX system. POSIX requires that the implicit return of the main thread results
1022in the same effects as if there were a call to ``exit``. This does not occur in
1023RTEMS.
1024
1025All access to any automatic variables allocated by the threads is lost when the
1026thread exits. Thus references (i.e. pointers) to local variables of a thread
1027should not be used in a global manner without care. As a specific example, a
1028pointer to a local variable should NOT be used as the return value.
1029
1030.. _pthread_detach:
1031
1032pthread_detach - Detach a Thread
1033--------------------------------
1034.. index:: pthread_detach
1035.. index:: detach a thread
1036
1037**CALLING SEQUENCE:**
1038
1039.. code-block:: c
1040
1041    #include <pthread.h>
1042    int pthread_detach(
1043        pthread_t thread
1044    );
1045
1046**STATUS CODES:**
1047
1048.. list-table::
1049 :class: rtems-table
1050
1051 * - ``ESRCH``
1052   - The thread specified is invalid.
1053 * - ``EINVAL``
1054   - The thread specified is not a joinable thread.
1055
1056**DESCRIPTION:**
1057
1058The ``pthread_detach`` routine is used to to indicate that storage for
1059``thread`` can be reclaimed when the thread terminates without another thread
1060joinging with it.
1061
1062**NOTES:**
1063
1064If any threads have previously joined with the specified thread, then they will
1065remain joined with that thread. Any subsequent calls to ``pthread_join`` on the
1066specified thread will fail.
1067
1068.. COMMENT: pthread_getconcurrency
1069
1070.. _pthread_getconcurrency:
1071
1072pthread_getconcurrency - Obtain Thread Concurrency
1073--------------------------------------------------
1074.. index:: pthread_getconcurrency
1075.. index:: obtain thread concurrency
1076
1077**CALLING SEQUENCE:**
1078
1079.. code-block:: c
1080
1081    #include <pthread.h>
1082    int pthread_getconcurrency(void);
1083
1084**STATUS CODES:**
1085
1086This method returns the current concurrency mapping value.
1087
1088**DESCRIPTION:**
1089
1090The ``pthread_getconcurrency`` method returns the number of user threads
1091mapped onto kernel threads. For RTEMS, user and kernel threads are mapped
10921:1 and per the POSIX standard this method returns 1 initially and
1093the value last set by ``pthread_setconcurrency`` otherwise.
1094
1095**NOTES:**
1096
1097NONE
1098
1099.. COMMENT: pthread_setconcurrency
1100
1101.. _pthread_setconcurrency:
1102
1103pthread_setconcurrency - Set Thread Concurrency
1104-----------------------------------------------
1105.. index:: pthread_setconcurrency
1106.. index:: obtain thread concurrency
1107
1108**CALLING SEQUENCE:**
1109
1110.. code-block:: c
1111
1112    #include <pthread.h>
1113    int pthread_setconcurrency(void);
1114
1115**STATUS CODES:**
1116
1117This method returns 0 on success.
1118
1119**DESCRIPTION:**
1120
1121The ``pthread_setconcurrency`` method requests the number of user threads
1122mapped onto kernel threads. Per the POSIX standard, this is considered
1123a request and may have no impact.
1124
1125For RTEMS, user and kernel threads are always mapped 1:1 and thus this
1126method has no change on the mapping. However, ``pthread_getconcurrency``
1127will return the value set.
1128
1129**NOTES:**
1130
1131NONE
1132
1133.. COMMENT: pthread_getattr_np
1134
1135.. _pthread_getattr_np:
1136
1137pthread_getattr_np - Get Thread Attributes
1138------------------------------------------
1139.. index:: pthread_getattr_np
1140.. index:: get thread attributes
1141
1142**CALLING SEQUENCE:**
1143
1144.. code-block:: c
1145
1146    #define _GNU_SOURCE
1147    #include <pthread.h>
1148    int pthread_getattr_np(
1149        pthread_t       thread,
1150        pthread_attr_t *attr
1151    );
1152
1153**STATUS CODES:**
1154
1155.. list-table::
1156 :class: rtems-table
1157
1158 * - ``ESRCH``
1159   - The thread specified is invalid.
1160 * - ``EINVAL``
1161   - The attribute pointer argument is invalid.
1162
1163**DESCRIPTION:**
1164
1165The ``pthread_getattr_np`` routine is used to obtain the attributes associated
1166with ``thread``.
1167
1168**NOTES:**
1169
1170Modification of the execution modes and priority through the Classic API may
1171result in a combination that is not representable in the POSIX API.
1172
1173.. _pthread_join:
1174
1175pthread_join - Wait for Thread Termination
1176------------------------------------------
1177.. index:: pthread_join
1178.. index:: wait for thread termination
1179
1180**CALLING SEQUENCE:**
1181
1182.. code-block:: c
1183
1184    #include <pthread.h>
1185    int pthread_join(
1186        pthread_t    thread,
1187        void       **value_ptr
1188    );
1189
1190**STATUS CODES:**
1191
1192.. list-table::
1193 :class: rtems-table
1194
1195 * - ``ESRCH``
1196   - The thread specified is invalid.
1197 * - ``EINVAL``
1198   - The thread specified is not a joinable thread.
1199 * - ``EDEADLK``
1200   - A deadlock was detected or thread is the calling thread.
1201
1202**DESCRIPTION:**
1203
1204The ``pthread_join`` routine suspends execution of the calling thread until
1205``thread`` terminates. If ``thread`` has already terminated, then this routine
1206returns immediately. The value returned by ``thread`` (i.e. passed to
1207``pthread_exit`` is returned in ``value_ptr``.
1208
1209When this routine returns, then ``thread`` has been terminated.
1210
1211**NOTES:**
1212
1213The results of multiple simultaneous joins on the same thread is undefined.
1214
1215If any threads have previously joined with the specified thread, then they will
1216remain joined with that thread. Any subsequent calls to ``pthread_join`` on the
1217specified thread will fail.
1218
1219If value_ptr is NULL, then no value is returned.
1220
1221.. _pthread_self:
1222
1223pthread_self - Get Thread ID
1224----------------------------
1225.. index:: pthread_self
1226.. index:: get thread id
1227
1228**CALLING SEQUENCE:**
1229
1230.. code-block:: c
1231
1232    #include <pthread.h>
1233    pthread_t pthread_self( void );
1234
1235**STATUS CODES:**
1236
1237The value returned is the ID of the calling thread.
1238
1239**DESCRIPTION:**
1240
1241This routine returns the ID of the calling thread.
1242
1243**NOTES:**
1244
1245NONE
1246
1247.. _pthread_equal:
1248
1249pthread_equal - Compare Thread IDs
1250----------------------------------
1251.. index:: pthread_equal
1252.. index:: compare thread ids
1253
1254**CALLING SEQUENCE:**
1255
1256.. code-block:: c
1257
1258    #include <pthread.h>
1259    int pthread_equal(
1260        pthread_t t1,
1261        pthread_t t2
1262    );
1263
1264**STATUS CODES:**
1265
1266.. list-table::
1267 :class: rtems-table
1268
1269 * - ``zero``
1270   - The thread ids are not equal.
1271 * - ``non-zero``
1272   - The thread ids are equal.
1273
1274**DESCRIPTION:**
1275
1276The ``pthread_equal`` routine is used to compare two thread IDs and determine
1277if they are equal.
1278
1279**NOTES:**
1280
1281The behavior is undefined if the thread IDs are not valid.
1282
1283.. _pthread_once:
1284
1285pthread_once - Dynamic Package Initialization
1286---------------------------------------------
1287.. index:: pthread_once
1288.. index:: dynamic package initialization
1289
1290**CALLING SEQUENCE:**
1291
1292.. code-block:: c
1293
1294    #include <pthread.h>
1295    pthread_once_t once_control = PTHREAD_ONCE_INIT;
1296    int pthread_once(
1297        pthread_once_t   *once_control,
1298        void            (*init_routine)(void)
1299    );
1300
1301**STATUS CODES:**
1302
1303NONE
1304
1305**DESCRIPTION:**
1306
1307The ``pthread_once`` routine is used to provide controlled initialization of
1308variables. The first call to ``pthread_once`` by any thread with the same
1309``once_control`` will result in the ``init_routine`` being invoked with no
1310arguments. Subsequent calls to ``pthread_once`` with the same ``once_control``
1311will have no effect.
1312
1313The ``init_routine`` is guaranteed to have run to completion when this routine
1314returns to the caller.
1315
1316**NOTES:**
1317
1318The behavior of ``pthread_once`` is undefined if ``once_control`` is automatic
1319storage (i.e. on a task stack) or is not initialized using
1320``PTHREAD_ONCE_INIT``.
1321
1322.. _pthread_setschedparam:
1323
1324pthread_setschedparam - Set Thread Scheduling Parameters
1325--------------------------------------------------------
1326.. index:: pthread_setschedparam
1327.. index:: set thread scheduling parameters
1328
1329**CALLING SEQUENCE:**
1330
1331.. code-block:: c
1332
1333    #include <pthread.h>
1334    int pthread_setschedparam(
1335        pthread_t           thread,
1336        int                 policy,
1337        struct sched_param *param
1338    );
1339
1340**STATUS CODES:**
1341
1342.. list-table::
1343 :class: rtems-table
1344
1345 * - ``EINVAL``
1346   - The scheduling parameters indicated by the parameter param is invalid.
1347 * - ``EINVAL``
1348   - The value specified by policy is invalid.
1349 * - ``EINVAL``
1350   - The scheduling policy was ``SCHED_SPORADIC`` and the specified
1351     replenishment period is less than the initial budget.
1352 * - ``EINVAL``
1353   - The scheduling policy was ``SCHED_SPORADIC`` and the specified low
1354     priority is invalid.
1355 * - ``ESRCH``
1356   - The thread indicated was invalid.
1357
1358**DESCRIPTION:**
1359
1360The ``pthread_setschedparam`` routine is used to set the scheduler parameters
1361currently associated with the thread specified by ``thread`` to the policy
1362specified by ``policy``. The contents of ``param`` are interpreted based upon
1363the ``policy`` argument.
1364
1365**NOTES:**
1366
1367As required by POSIX, RTEMS defines the feature symbol
1368``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
1369to which this routine belongs is supported.
1370
1371.. _pthread_getschedparam:
1372
1373pthread_getschedparam - Get Thread Scheduling Parameters
1374--------------------------------------------------------
1375.. index:: pthread_getschedparam
1376.. index:: get thread scheduling parameters
1377
1378**CALLING SEQUENCE:**
1379
1380.. code-block:: c
1381
1382    #include <pthread.h>
1383    int pthread_getschedparam(
1384        pthread_t           thread,
1385        int                *policy,
1386        struct sched_param *param
1387    );
1388
1389**STATUS CODES:**
1390
1391.. list-table::
1392 :class: rtems-table
1393
1394 * - ``EINVAL``
1395   - The policy pointer argument is invalid.
1396 * - ``EINVAL``
1397   - The scheduling parameters pointer argument is invalid.
1398 * - ``ESRCH``
1399   - The thread indicated by the parameter thread is invalid.
1400
1401**DESCRIPTION:**
1402
1403The ``pthread_getschedparam`` routine is used to obtain the scheduler policy
1404and parameters associated with ``thread``.  The current policy and associated
1405parameters values returned in``policy`` and ``param``, respectively.
1406
1407**NOTES:**
1408
1409As required by POSIX, RTEMS defines the feature symbol
1410``_POSIX_THREAD_PRIORITY_SCHEDULING`` to indicate that the family of routines
1411to which this routine belongs is supported.
1412
1413.. COMMENT: pthread_getaffinity_np
1414
1415.. _pthread_getaffinity_np:
1416
1417pthread_getaffinity_np - Get Thread Affinity
1418--------------------------------------------
1419
1420**CALLING SEQUENCE:**
1421
1422.. code-block:: c
1423
1424    #define _GNU_SOURCE
1425    #include <pthread.h>
1426    int pthread_getaffinity_np(
1427        const pthread_t       id,
1428        size_t                cpusetsize,
1429        cpu_set_t            *cpuset
1430    );
1431
1432**STATUS CODES:**
1433
1434.. list-table::
1435 :class: rtems-table
1436
1437 * - ``EFAULT``
1438   - The cpuset pointer argument is invalid.
1439 * - ``EINVAL``
1440   - The ``cpusetsize`` does not match the value of ``affinitysetsize`` field
1441     in the thread attribute object.
1442
1443**DESCRIPTION:**
1444
1445The ``pthread_getaffinity_np`` routine is used to obtain the ``affinity.set``
1446field from the thread control object associated with the ``id``.  The value of
1447this field is returned in ``cpuset``.
1448
1449**NOTES:**
1450
1451NONE
1452
1453.. COMMENT: pthread_setaffinity_np
1454
1455.. _pthread_setaffinity_np:
1456
1457pthread_setaffinity_np - Set Thread Affinity
1458--------------------------------------------
1459
1460**CALLING SEQUENCE:**
1461
1462.. code-block:: c
1463
1464    #define _GNU_SOURCE
1465    #include <pthread.h>
1466    int pthread_setaffinity_np(
1467        pthread_t          id,
1468        size_t             cpusetsize,
1469        const cpu_set_t   *cpuset
1470    );
1471
1472**STATUS CODES:**
1473
1474.. list-table::
1475 :class: rtems-table
1476
1477 * - ``EFAULT``
1478   - The cpuset pointer argument is invalid.
1479 * - ``EINVAL``
1480   - The ``cpusetsize`` does not match the value of ``affinitysetsize`` field
1481     in the thread attribute object.
1482 * - ``EINVAL``
1483   - The ``cpuset`` did not select a valid cpu.
1484 * - ``EINVAL``
1485   - The ``cpuset`` selected a cpu that was invalid.
1486
1487**DESCRIPTION:**
1488
1489The ``pthread_setaffinity_np`` routine is used to set the ``affinityset`` field
1490of the thread object ``id``.  The value of this field is returned in ``cpuset``
1491
1492**NOTES:**
1493
1494NONE
Note: See TracBrowser for help on using the repository browser.