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 X/Open CAE Specification, System Interfaces and Headers, Issue 5 (also known as XSH5), which is part of the new UNLX98 brand. XSH5 requires conformance to the POSIX.1-1996 standard, which includes the POSIX.1b and POSIX.1c amendments. The XSH5 specification also adds a set of extensions to POSIX. This section discusses the XSH5 extensions that specifically affect threaded programs. You can recognize a system conforming to XSH5 by a definition for the _XOPEN_VERSION symbol, in <unistd.h>, to the value 500 or higher.

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 stacksize attribute is supported.

• _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 fast, recursive, and nonrecursive mutex kinds. The XSH5 specification changes the attribute name from 'kind' to 'type,' renames fast to default, renames nonrecursive to errorcheck, and adds a new type, normal (Table 10.1).

A normal mutex is not allowed to detect deadlock errors — that is, a thread will hang if it tries to lock a normal mutex that it already owns. The default mutex type, like the DCE fast mutex,[11] provides implementation-defined error checking. That is, default may be mapped to one of the other standard types or may be something entirely different.

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 XSH5 mutex types

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

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×