Movatterモバイル変換


[0]ホーム

URL:


What is UNIX

1. Introduction

Name Space

Threads Types

2. UNIX System Threads API

DescriptionRegister functions to be called during fork() execution
ErrorsENOMEM
Notes

.

Threads Attributes

All threads attributes are set in a thread attributes object bya function of the form:

Description and Value(s)
size_t stacksizeThe thread's stack size. >= PTHREAD_STACK_MIN
void *stackaddrThe thread's stack address. For example, void *stack
size_t guardsizeThe thread's stack guard size. The default size is PAGESIZE bytes.
int detachstateThe thread's detach state:

PTHREAD_CREATE_DETACHED,PTHREAD_CREATE_JOINABLE

int contentionscopeThe thread's scope.

PTHREAD_SCOPE_SYSTEM, PTHREAD_SCOPE_PROCESS

int inheritschedThe thread's scheduling inheritence PTHREAD_INHERIT_SCHED,PTHREAD_EXPLICIT_SCHED
int schedpolicyThe thread's scheduling policy.

SCHED_FIFO, SCHED_RR, SCHED_OTHER

struct sched_param schedparamThe thread's scheduling parameters.

See POSIX.1 Section 13


pthread_attr_init

Synopsis
DescriptionInitialize a thread attributes object.
ErrorsENOMEM

pthread_attr_destroy

Synopsis
DescriptionDestroy a thread attributes object
ErrorsNone

The other attribute related functions are listed below:

Thread Management

DescriptionCreate a new thread of execution
ErrorsEAGAIN, EINVAL
NotesMaximum number of PTHREADS_THREADS_MAX per process

pthread_detach

Synopsis
DescriptionSet the detachstate of the specified thread to PTHREAD_CREATE_DETACHED
ErrorsEINVAL,ESRCH

pthread_safe

Synopsis
DescriptionReturn the thread ID of the calling thread
Errors None


pthread_equal

Synopsis
DescriptionCompare two thread Ids for equality
ErrorsNone

pthread_exit

Synopsis
DescriptionTerminate the calling thread
ErrorsNone

pthread_join

Synopsis
DescriptionSynchronize with the termination of a thread
ErrorsEINVAL,ESRCH,EDEADLK
NotesThis function is a cancellation point

pthread_getschedparam

Synopsis

DescriptionGet the scheduling policy and parameters of the specified thread
ErrorsENOSYS,ESRCH
NotesDependent on support of _XOPEN_REALTIME_THREADS

pthread_setschedparam

Synopsis

DescriptionSet the scheduling policy and parameters of the specified thread
ErrorsENOSYS,EINVAL,ENOTSUP,EPERM,ESRCH
NotesDependent on support of _XOPEN_REALTIME_THREADS

Mutex Attributes

All mutex attributes are set in a mutex attribute object by afunction of the form:

Description and Value(s)
int protocolDefine the scheduling classes for mutex locks PTHREAD_PRIO_NONE,PTHREAD_PRIO_PROTECT,

PTHREAD_PRIO_INHERIT

int psharedDefines whether a mutex is shared with other processes. PTHREAD_PROCESS_SHARED, PTHREAD_PROCESS_PRIVATE
int prioceilingUsed for mutex attribute priority ceiling values. See POSIX.1 section 13
int typeApplication defined mutex locking

PTHREAD_MUTEX_NORMAL,PTHREAD_MUTEX_RECURSIVE,
PTHREAD_MUTEX_ERRORCHECK,PTHREAD_MUTEX_DEFAULT


pthread_mutexattr_init

Synopsis
DescriptionInitialize a mutex attribute object
ErrorsENOMEM

pthread_mutexattr_destroy

Synopsis
DescriptionDestroy a mutex attribute object
ErrorsEINVAL

The mutex attribute manipulation routines supported are as follows:

Mutex Usage

DescriptionInitialize a mutex
ErrorsEAGAIN,ENOMEM,EPERM,EBUSY,EINVAL

pthread_mutex_destroy

Synopsis
DescriptionDestroy a mutex
ErrorsEBUSY,EINVAL

pthread_mutex_getprioceiling

Synopsis
DescriptionGet the prioceiling value of the specified mutex
ErrorsENOSYS, EINVAL,EPERM
NotesThis is dependent on _XOPEN_REALTIME_THREADS

pthread_mutex_setprioceiling

Synopsis
DescriptionSet the prioceiling value and return the old prioceiling value in the specified mutex
ErrorsENOSYS,EINVAL,EPERM
NotesThis is dependent on _XOPEN_REALTIME_THREADS

pthread_mutex_lock

Synopsis
DescriptionAcquire the indicated mutex
ErrorsEINVAL,EDEADLK

pthread_mutex_trylock

Synopsis
DescriptionAttempt to acquire the indicated mutex
ErrorsEINVAL,EBUSY

pthread_mutex_unlock

Synopsis
DescriptionRelease the previously acquired mutex
ErrorsEINVAL,EPERM

Once-only execution

Initialize a once control variable:

Description Execute init_routine once
ErrorsNone

Condition Variable Attributes

All condition variable attributes are set in a condition variableattribute object by a function of the form:

Description and Value(s)
int psharedDefines whether a condition variable is shared with other processes.

PTHREAD_PROCESS_SHARED,PTHREAD_PROCESS_PRIVATE

The functions are:

DescriptionInitialize a condition variable attribute object
ErrorsENOMEM

pthread_condattr_destroy

Synopsis
DescriptionDestroy a condition variable attribute object
ErrorsEINVAL


Condition Variable Usage

pthread_cond_init

Synopsis
DescriptionInitialize a condition variable
ErrorsEAGAIN,ENOMEM,EBUSY,EINVAL

pthread_cond_destroy

Synopsis
DescriptionDestroy a condition variable
ErrorsEBUSY,EINVAL

pthread_cond_signal

Synopsis
DescriptionUnblock at least one thread currently blocked in the specified condition variable
ErrorsEINVAL

pthread_cond_broadcast

Synopsis
DescriptionUnblock all threads currently blocked on the specified condition variable
ErrorsEINVAL

pthread_cond_wait

Synopsis
DescriptionBlock on the specified condition variable
ErrorsEINVAL
NotesThis function is a cancellation point

pthread_cond_timedwait

Synopsis
DescriptionBlock on the specified condition variable not longer than the specified absolute time
ErrorsETIMEDOUT,EINVAL
NotesThis function is a cancellation point


Thread Specific Data

pthread_key_create

Synopsis
DescriptionCreate a thread-specific data key
ErrorsEAGAIN,ENOMEM
NotesThere is a system limit of PTHREAD_KEYS_MAX per process.

There is a system limit of PTHREAD_DESTRUCTOR_ITERATIONS calls to destructor per thread exit

.

pthread_key_delete

Synopsis
DescriptionDestroy a thread-specific data key
ErrorsEINVAL

pthread_getspecific

Synopsis
DescriptionReturn the value bound to the given key for the calling thread
ErrorsENOMEM,EINVAL

pthread_setspecific

Synopsis
DescriptionSet the value for the given key in the calling thread
ErrorsENOMEM,EINVAL


Signal Management

pthread_sigmask

Synopsis

DescriptionExamine or change calling threads signal mask
ErrorsEINVAL
NotesThe value of how can be SIG_BLOCK,SIG_UNBLOCK,SIG_SETMASK

pthread_kill

Synopsis

DescriptionDeliver signal to indicated thread
Errors ESRCH,EINVAL


sigwait

Synopsis
DescriptionSynchronously accept a signal
ErrorsEINVAL,EINTR
NotesThis function is a cancellation point

Cancellation

pthread_setcancelstate

Synopsis
DescriptionSet the cancellation state for the calling thread
ErrorsEINVAL
NotesValues forstate are PTHREAD_CANCEL_ENABLE,PTHREAD_CANCEL_DISABLE

pthread_setcanceltype

Synopsis
DescriptionSet the cancellation type for the calling thread
Errors EINVAL
NotesValues fortype are PTHREAD_CANCEL_ENABLE,PTHREAD_CANCEL_ASYNCHRONOUS

pthread_cancel

Synopsis
DescriptionCancel the specified thread
ErrorsESRCH
NotesThreads that have been cancelled terminate with a status of PTHREAD_CANCELLED

pthread_testcancel

Synopsis
DescriptionIntroduce a cancellation point
ErrorsNone
NotesThis function is a cancellation point


pthread_cleanup_push

Synopsis
DescriptionPush an item onto the cancellation stack
ErrorsNone


pthread_cleanup_pop

Synopsis
DescriptionPop the top item from the cancellation stack and optionally execute it
ErrorsNone
Notespush and pop operations must appear at the same lexical level.executetakes the values 0 or 1.


Concurrency

pthread_getconcurrency

Synopsis
DescriptionGet level of concurrency
ErrorsNone

pthread_setconcurrency

Synopsis
DescriptionSet level of concurrency
ErrorsEINVAL,EAGAIN



Read-Write Locks

pthread_rwlock_init

Synopsis
DescriptionInitialize a read-write lock object
ErrorsEAGAIN,ENOMEM,EPERM,EBUSY,EINVAL

pthread_rwlock_destory

Synopsis
DescriptionDestroy a read-write lock object
ErrorsEBUSY,EINVAL

pthread_rwlock_rdlock

Synopsis
DescriptionLock a read-write lock object for reading
ErrorsEINVAL,EDEADLCK,EAGAIN

pthread_rwlock_tryrdlock

Synopsis
DescriptionLock a read-write lock for reading, unless there is an existing write lock or blocked writers
ErrorsEBUSY,EINVAL,EDEADLCK,,EAGAIN

pthread_rwlock_wrlock

Synopsis
DescriptionLock a read-write lock object for writing, block if necessary until the lock becomes available
ErrorsEINVAL,EDEADLCK



pthread_rwlock_trywrlock

Synopsis
DescriptionLock a read-write lock for writing, unless there are any existing read or write locks
ErrorsEBUSY,EINVAL,EDEADLCK

pthread_rwlock_unlock

Synopsis
DescriptionUnlock a read-write lock object
ErrorsEINVAL,EPERM

pthread_rwlockattr_init

Synopsis
DescriptionInitialize a read-write lock attributes object
ErrorsENOMEM

pthread_rwlockattr_destroy

Synopsis
DescriptionDestroy a read-write lock attributes object
ErrorsEINVAL

pthread_rwlockattr_getpshared

Synopsis
DescriptionGet the value of the process-shared attribute of a read-write lock attributes object
ErrrorsEINVAL

pthread_rwlockattr_setpshared

Synopsis
DescriptionSet the value of the process-shared attribute of a read-write lock attributes object
ErrrorsEINVAL


Atomic Input/Output

pread

Synopsis
DescriptionAtomic read of data from file into buffer
ErrorsSee read()

pwrite

Synopsis
DescriptionAtomic write of data from buffer into file
ErrorsSee write()

Realtime Threads Feature Group

The following threads functions are only supported on UNIX systems if the Realtime Threads Feature group is supported (denoted bythe symbol _XOPEN_REALTIME_THREADS in <unistd.h>).


Thread-safety

The following functions are not guaranteed to be thread-safe onall UNIX systems:

The functions ctermid() and tmpnam() need not be thread-safe ifpassed a NULL argument.

The functions in the Legacy Feature Group need not be thread-safe.

New Threads Related Functions

The following functions offer alternate functionality for implementingthread-safe code, some of these

functions are thread-safe versions of common POSIX.1 functions,some are non thread-safe fast functions to be used with the lockingfacilities also defined in this section.

asctime_r

Synopsis

DescriptionThread safe version of

ctime_r

Synopsis

DescriptionThread safe version of

flockfile

Synopsis

Description

ftrylockfile

Synopsis

Description

funlockfile

Synopsis

Description

getc_unlocked

Synopsis

DescriptionFast version of getc() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile()


getchar_unlocked

Synopsis

DescriptionFast version of getchar() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile()

getgrgid_r

Synopsis

DescriptionThread safe version of getgrgid()


getgrnam_r

Synopsis
DescriptionThread safe version of getgrnam()

getpwnam_r

Synopsis
Description Thread safe version of getpwnam()


getpwuid_r

Synopsis
DescriptionThread safe version of getpwuid()



gmtime_r

Synopsis

DescriptionThread safe version of gmtime()

localtime_r

Synopsis

DescriptionThread safe version of localtime()

putc_unlocked

Synopsis

DescriptionFast version of putc() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile()

putchar_unlocked

Synopsis

DescriptionFast version of putchar() to be used in conjunction with flockfile(), ftrylockfile() and funlockfile()

rand_r

Synopsis

DescriptionThread safe version of rand()


readdir_r

Synopsis
DescriptionThread safe version of readdir()

strtok_r

Synopsis
DescriptionThread safe version of strtok()



Read other technical papers.

Read ordownload the complete Single UNIX Specification fromhttp://www.UNIX-systems.org/go/unix.

Copyright © 1997-1998 The Open Group

UNIX is a registered trademark of The Open Group.


[8]ページ先頭

©2009-2025 Movatter.jp