pthread_mutexattr_t *attr, int type);
Read/write locks:
int pthread_rwlock_init (pthread_rwlock_t *rwlock,
const pthread_rwlockattr_t *attr); int pthread_rwlock_destroy (pthread_rwlock_t *rwlock); pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock); int pthread_rwlock_tryrdlock (
pthread_rwlock_t *rwlock); int pthread_rwlock_unlock (pthread_rwlock_t *rwlock); int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock); int pthread_rwlock_trywrlock (
pthread_rwlock_t *rwlock); int pthread_rwlockattr_init (
pthread_rwlockattr_t *attr); int pthread_rwlockattr_destroy (
pthread_rwlockattr_t *attr); int pthread_rwlockattr_getpshared (
const pthread_rwlockattr_t *attr, int *pshared); int pthread_rwlockattr_setpshared (
pthread_rwlockattr_t *attr, int pshared);
Parallel I/O:
size_t pread (int fildes,
void *buf, size_t nbyte, off_t offset); size_t pwrite (int fildes,
const void *buf, size_t nbyte, off_t offset);
Miscellaneous:
int pthread_attr_getguardsize (
const pthread_attr_t *attr, size_t *guardsize); int pthread_attr_setguardsize (
pthread_attr_t *attr, size_t guardsize); int pthread_getconcurrency (); int pthread_setconcurrency (int new_level);
X/Open, which is part of The Open Group, owns the UNIX trademark and develops UNIX industry portability specifications and brands. The X/Open brands include XPG3, XPG4, UNLX93, and UNLX95. UNLX95 is also known as 'SPEC1170' or the 'Single UNIX Specification.'
X/Open recently published the
The most valuable contribution of UNLX98 to the threaded programming industry, however, is possibly the development of a standardized, portable testing system. A number of complicated issues arise when developing an implementation of Pthreads, and some subtle aspects of the standard are ambiguous. Such an industry-wide testing system will require all vendors implementing UNLX98 branded systems to agree on interpretations of Pthreads.
10.1.1 POSIX options for XSH5
Some of the features that are options in the Pthreads standard are required by XSH5. If your code relies on these Pthreads options, it will work on any system conforming to XSH5:
• _POSIX_THREADS: Threads are supported.
• _POSIX_THREAD_ATTR_STACKADDR: The stackaddr attribute is supported.
• _POSIX_THREAD_ATTR_STACKSIZE: The
• _POSIX_THREAD_PROCESS_SHARED: Mutexes, condition variables, and XSH5 read/write locks can be shared between processes.
• _POSIX_THREAD_SAFE_FUNCTIONS: The Pthreads thread-safe functions are supported.
Several additional Pthreads options are 'bundled' into the XSH5 realtime threads option group. If your system conforms to XSH5 and supports the _XOPEN_ REALTIME_THREADS option, then these Pthreads options are also supported:
• _POSIX_THREAD_PRIORITY_SCHEDULING: Realtime priority scheduling is supported.
• _POSIX_THREAD_PRIO_PROTECT: Priority ceiling mutexes are supported.
• _POSIX_THREAD_PRIO_INHERIT: Priority inheritance mutexes are supported.
10.1.2 Mutex type
The DCE threads package provided an extension that allowed the programmer to specify the 'kind' of mutex to be created. DCE threads supplied
A
Mutex type | Definition |
PTHREAD_MUTEX_NORMAL | Basic mutex with no specific error checking built in. Does not report a deadlock error. |
PTHREAD__MUTEX__RECURSIVE | Allows any thread to lock the mutex 'recursively' — it must unlock an equal number of times to release the mutex. |
PTHREAD_MUTEX_ERRORCHECK | Detects and reports simple usage errors — an attempt to unlock a mutex that's not locked by the calling thread (or that isn't locked at all), or an attempt to relock a mutex the thread already owns. |
PTHREAD__MUTEX__DEFAULT | The default mutex type, with very loose semantics to allow unfettered innovation and experimentation. May be mapped to any of the other three defined types, or may be something else entirely. |
TABLE 10.1
As an application developer, you can use any of the mutex types almost interchangeably as long as your code does not depend on the implementation to detect (or fail to detect) any particular errors. Never write code that