1pthread_rwlock_init(3C) Standard C Library Functions pthread_rwlock_init(3C)
2
3
4
6 pthread_rwlock_init, pthread_rwlock_destroy - initialize or destroy
7 read-write lock object
8
10 cc -mt [ flag... ] file... -lpthread [ library... ]
11 #include <pthread.h>
12
13 int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
14 const pthread_rwlockattr_t *restrict attr);
15
16
17 int pthread_rwlock_destroy(pthread_rwlock_t **rwlock);
18
19
20 pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER;
21
22
24 The pthread_rwlock_init() function initializes the read-write lock ref‐
25 erenced by rwlock with the attributes referenced by attr. If attr is
26 NULL, the default read-write lock attributes are used; the effect is
27 the same as passing the address of a default read-write lock
28 attributes object. Once initialized, the lock can be used any number
29 of times without being re-initialized. Upon successful initialization,
30 the state of the read-write lock becomes initialized and unlocked.
31 Results are undefined if pthread_rwlock_init() is called specifying an
32 already initialized read-write lock. Results are undefined if a read-
33 write lock is used without first being initialized.
34
35
36 If the pthread_rwlock_init() function fails, rwlock is not initialized
37 and the contents of rwlock are undefined.
38
39
40 The pthread_rwlock_destroy() function destroys the read-write lock
41 object referenced by rwlock and releases any resources used by the
42 lock. The effect of subsequent use of the lock is undefined until the
43 lock is re-initialized by another call to pthread_rwlock_init(). An
44 implementation may cause pthread_rwlock_destroy() to set the object
45 referenced by rwlock to an invalid value. Results are undefined if
46 pthread_rwlock_destroy() is called when any thread holds rwlock.
47 Attempting to destroy an uninitialized read-write lock results in
48 undefined behaviour. A destroyed read-write lock object can be re-ini‐
49 tialized using pthread_rwlock_init(); the results of otherwise refer‐
50 encing the read-write lock object after it has been destroyed are
51 undefined.
52
53
54 In cases where default read-write lock attributes are appropriate, the
55 macro PTHREAD_RWLOCK_INITIALIZER can be used to initialize read-write
56 locks that are statically allocated. The effect is equivalent to
57 dynamic initialization by a call to pthread_rwlock_init() with the
58 parameter attr specified as NULL, except that no error checks are per‐
59 formed.
60
62 If successful, the pthread_rwlock_init() and pthread_rwlock_destroy()
63 functions return 0. Otherwise, an error number is returned to indi‐
64 cate the error.
65
67 The pthread_rwlock_init() and pthread_rwlock_destroy() functions will
68 fail if:
69
70 EINVAL The value specified by attr is invalid.
71
72
73 EINVAL The value specified by rwlock is invalid.
74
75
77 See attributes(5) for descriptions of the following attributes:
78
79
80
81
82 ┌─────────────────────────────┬─────────────────────────────┐
83 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
84 ├─────────────────────────────┼─────────────────────────────┤
85 │Interface Stability │Standard │
86 ├─────────────────────────────┼─────────────────────────────┤
87 │MT-Level │MT-Safe │
88 └─────────────────────────────┴─────────────────────────────┘
89
91 pthread_rwlock_rdlock(3C), pthread_rwlock_unlock(3C),
92 pthread_rwlock_wrlock(3C), pthread_rwlockattr_init(3C), attributes(5),
93 standards(5)
94
95
96
97SunOS 5.11 23 mar 2005 pthread_rwlock_init(3C)