summaryrefslogtreecommitdiffstats
path: root/doc/new_chapters/thread.t
blob: 9add33dfefeb09a3b342d77b24bafcc9b34b4d27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
@c
@c  COPYRIGHT (c) 1988-1998.
@c  On-Line Applications Research Corporation (OAR).
@c  All rights reserved.
@c
@c  $Id$
@c

@chapter Thread Manager

@section Introduction

The thread manager ...

The directives provided by the thread manager are:

@itemize @bullet
@item @code{pthread_attr_init} - 
@item @code{pthread_attr_destroy} - 
@item @code{pthread_attr_setdetachstate} - 
@item @code{pthread_attr_getdetachstate} - 
@item @code{pthread_attr_setstacksize} - 
@item @code{pthread_attr_getstacksize} - 
@item @code{pthread_attr_setstackaddr} - 
@item @code{pthread_attr_getstackaddr} - 
@item @code{pthread_attr_setscope} - 
@item @code{pthread_attr_getscope} - 
@item @code{pthread_attr_setinheritsched} - 
@item @code{pthread_attr_getinheritsched} - 
@item @code{pthread_attr_setschedpolicy} - 
@item @code{pthread_attr_getschedpolicy} - 
@item @code{pthread_attr_setschedparam} - 
@item @code{pthread_attr_getschedparam} - 
@item @code{pthread_create} - 
@item @code{pthread_exit} - 
@item @code{pthread_detach} - 
@item @code{pthread_join} - 
@item @code{pthread_self} - 
@item @code{pthread_equal} - 
@item @code{pthread_once} - 
@item @code{pthread_setschedparam} - 
@item @code{pthread_getschedparam} - 
@end itemize

@section Background

@subsection Thread Attributes

Thread attributes are utilized only at thread creation time.

@table @b
@item stack address
is the address of the optionally user specified stack area for this thread.
If this value is NULL, then RTEMS allocates the memory for the thread stack 
from the RTEMS Workspace Area.  Otherwise, this is the user specified
address for the memory to be used for the thread's stack.  Each thread must
have a distinct stack area.  Each processor family has different alignment
rules which should be followed.

@item stack size
is the minimum desired size for this thread's stack area.
If the size of this area as specified by the stack size attribute 
is smaller than the minimum for this processor family and the stack 
is not user specified, then RTEMS will automatically allocate a 
stack of the minimum size for this processor family.

@item contention scope
specifies the scheduling contention scope.  RTEMS only supports the
PTHREAD_SCOPE_PROCESS scheduling contention scope.

@item scheduling inheritance
specifies whether a user specified or the scheduling policy and 
parameters of the currently executing thread are to be used.  When 
this is PTHREAD_INHERIT_SCHED, then the scheduling policy and 
parameters of the currently executing thread are inherited by 
the newly created thread.

@item scheduling policy and parameters
specify the manner in which the thread will contend for the processor.
The scheduling parameters are interpreted based on the specified policy.
All policies utilize the thread priority parameter.

@end table

@section Operations

@section Directives

This section details the thread manager's directives.
A subsection is dedicated to each of this manager's directives
and describes the calling sequence, related constants, usage,
and status codes.

@page
@subsection pthread_attr_init

@subheading CALLING SEQUENCE:


@example
#include <pthread.h>

int pthread_attr_init(
  pthread_attr_t  *attr
);
@end example

@subheading STATUS CODES:

@table @b
@item EINVAL
The attribute pointer argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_destroy

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>
 
int pthread_attr_destroy(
  pthread_attr_t  *attr
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setdetachstate

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>
 
int pthread_attr_setdetachstate(
  pthread_attr_t  *attr,
  int              detachstate
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item EINVAL
The detachstate argument is invalid.
 
@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getdetachstate

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>
 
int pthread_attr_getdetachstate(
  const pthread_attr_t  *attr,
  int                   *detachstate
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item EINVAL
The detatchstate pointer argument is invalid.

@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setstacksize

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>
 
int pthread_attr_setstacksize(
  pthread_attr_t  *attr,
  size_t           stacksize
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

If the specified stacksize is below the minimum required for this CPU, then
the stacksize will be set to the minimum for this CPU.

@page
@subsection pthread_attr_getstacksize

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getstacksize(
  const pthread_attr_t  *attr,
  size_t                *stacksize
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item EINVAL
The stacksize pointer argument is invalid.

@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setstackaddr

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>
 
int pthread_attr_setstackaddr(
  pthread_attr_t  *attr,
  void            *stackaddr
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getstackaddr

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getstackaddr(
  const pthread_attr_t  *attr,
  void                 **stackaddr
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item EINVAL
The stackaddr pointer argument is invalid.

@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setscope

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_setscope(
  pthread_attr_t  *attr,
  int              contentionscope
);
@end example

@subheading STATUS CODES:

@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The contention scope specified is not valid.

@item ENOTSUP
The contention scope specified (PTHREAD_SCOPE_SYSTEM) is not supported.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getscope

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getscope(
  const pthread_attr_t  *attr,
  int                   *contentionscope
);
@end example

@subheading STATUS CODES:

@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The contentionscope pointer argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setinheritsched

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_setinheritsched(
  pthread_attr_t  *attr,
  int              inheritsched
);
@end example

@subheading STATUS CODES:

@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The specified scheduler inheritance argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getinheritsched

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getinheritsched(
  const pthread_attr_t  *attr,
  int                   *inheritsched
);
@end example

@subheading STATUS CODES:
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The inheritsched pointer argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setschedpolicy

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_setschedpolicy(
  pthread_attr_t  *attr,
  int              policy
);
@end example

@subheading STATUS CODES:
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item ENOTSUP
The specified scheduler policy argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getschedpolicy

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getschedpolicy(
  const pthread_attr_t  *attr,
  int                   *policy
);
@end example

@subheading STATUS CODES:
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The specified scheduler policy argument pointer is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_setschedparam

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_setschedparam(
  pthread_attr_t            *attr,
  const struct sched_param   param
);
@end example

@subheading STATUS CODES:
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.
 
@item EINVAL
The specified scheduler parameter argument is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_attr_getschedparam

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_attr_getschedparam(
  const pthread_attr_t  *attr,
  struct sched_param    *param
);
@end example

@subheading STATUS CODES:
@table @b
@item EINVAL
The attribute pointer argument is invalid.

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The specified scheduler parameter argument pointer is invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_create

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_create(
  pthread_t             *thread,
  const pthread_attr_t  *attr,
  void                 (*start_routine)( void * ),
  void                  *arg
);
@end example

@subheading STATUS CODES:

@table @b

@item EINVAL
The attribute set is not initialized.

@item EINVAL
The user specified a stack address and the size of the area was not 
large enough to meet this processor's minimum stack requirements.

@item EINVAL
The specified scheduler inheritance policy was invalid.

@item ENOTSUP
The specified contention scope was PTHREAD_SCOPE_PROCESS.

@item EINVAL
The specified thread priority was invalid.

@item EINVAL
The specified scheduling policy was invalid.

@item EINVAL
The scheduling policy was SCHED_SPORADIC and the specified replenishment
period is less than the initial budget.

@item EINVAL
The scheduling policy was SCHED_SPORADIC and the specified low priority
is invalid.

@item EAGAIN
The system lacked the necessary resources to create another thread, or the
self imposed limit on the total number of threads in a process
PTHREAD_THREAD_MAX would be exceeded.
 
@item EINVAL
Invalid argument passed.

@end table
 
@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_exit

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

void pthread_exit(
  void   *status
);
@end example

@subheading STATUS CODES:
@table @b
@item NONE
 
@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_detach

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_detach(
  pthread_t   thread
);
@end example

@subheading STATUS CODES:
@table @b
@item ESRCH
The thread specified is invalid.
 
@item EINVAL
The thread specified is not a joinable thread.
 
@end table

@subheading DESCRIPTION:

@subheading NOTES:

If any threads have previously joined with the specified thread, then they
will remain joined with that thread.  Any subsequent calls to pthread_join
on the specified thread will fail.

@page
@subsection pthread_join

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_join(
  pthread_t   thread,
  void      **value_ptr
);
@end example

@subheading STATUS CODES:
@table @b
@item ESRCH
The thread specified is invalid.
 
@item EINVAL
The thread specified is not a joinable thread.
 
@item EDEADLK
A deadlock was detected or thread is the calling thread.
 
@end table

@subheading DESCRIPTION:

@subheading NOTES:

If any threads have previously joined with the specified thread, then they
will remain joined with that thread.  Any subsequent calls to pthread_join
on the specified thread will fail.

If value_ptr is NULL, then no value is returned.

@page
@subsection pthread_self

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

pthread_t pthread_self( void );
@end example

@subheading STATUS CODES:

This routine returns the id of the calling thread.

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_equal

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_equal(
  pthread_t  t1,
  pthread_t  t2
);
@end example

@subheading STATUS CODES:

@table @b
@item zero
The thread ids are not equal.
 
@item non-zero
The thread ids are equal.
 
@end table

@subheading DESCRIPTION:

@subheading NOTES:

The behavior is undefined if the thread IDs are not valid.

@page
@subsection pthread_once

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

pthread_once_t once_control = PTHREAD_ONCE_INIT;

int pthread_once(
  pthread_once_t  *once_control,
  void           (*init_routine)(void)
);
@end example

@subheading STATUS CODES:

NONE

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_setschedparam

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_setschedparam(
  pthread_t           thread,
  int                 policy,
  struct sched_param *param
);
@end example

@subheading STATUS CODES:

@table @b
@item EINVAL
The scheduling parameters indicated by the parameter param is invalid.

@item EINVAL
The value specified by policy is invalid.

@item EINVAL
The scheduling policy was SCHED_SPORADIC and the specified replenishment
period is less than the initial budget.

@item EINVAL
The scheduling policy was SCHED_SPORADIC and the specified low priority
is invalid.

@item ESRCH
The thread indicated was invalid.

@end table

@subheading DESCRIPTION:

@subheading NOTES:

@page
@subsection pthread_getschedparam

@subheading CALLING SEQUENCE:

@example
#include <pthread.h>

int pthread_getschedparam(
  pthread_t           thread,
  int                *policy,
  struct sched_param *param
);
@end example

@subheading STATUS CODES:
 
@table @b
@item EINVAL
The policy pointer argument is invalid.

@item EINVAL
The scheduling parameters pointer argument is invalid.

@item ESRCH
The thread indicated by the parameter thread is invalid.
 
@end table

@subheading DESCRIPTION:

@subheading NOTES: