Книга: Programming with POSIX® Threads

9.3.12 Signals

9.3.12 Signals

Pthreads provides functions that extend the POSIX signal model to support multithreaded processes. All threads in a process share the same signal actions. Each thread has its own pending and blocked signal masks. The process also has a pending signal mask so that asynchronous signals can pend against the process when all threads have the signal blocked. In a multithreaded process, the behavior of sigprocmask is undefined.

pthread_kill

int pthread_kill (

pthread_t thread,

int sig) ;

Request that the signal sig be delivered to thread. If sig is 0, no signal is sent, but error checking is performed. If the action of the signal is to terminate, stop, or continue, then the entire process is affected.

References: 6.6.3 Headers: <signal.h>

Errors: [ESRCH] no thread corresponding to thread.

[EINVAL] sig is an invalid signal number. Hint: To terminate a thread, use cancellation.

pthread_sigmask

int pthread_sigmask (

int how,

const sigset_t *set,

sigset_t *oset);

Control the masking of signals within the calling thread.

how

References: 6.6.2 Headers: <signal.h>

Errors: [EINVAL] how is not one of the defined values.

Hint: You cannot prevent delivery of asynchronous signals to the process

unless the signal is blocked in all threads.

sigtimedwait

int sigtimedwait (

const sigset_t *set,

siginfo_t *info,

const struct timespec *timeout);

If a signal in set is pending, atomically clear it from the set of pending signals and return the signal number in the si_signo member of info. The cause of the signal

how
SIG_ BLOCK Resulting set is the union of the
current set and the argument set.
SIG_ UNBLOCK Resulting set is the intersection of
the current set and the argument
set.
SIG_ _SETMASK Resulting set is the set pointed to
by the argument set.

shall be stored in the si_code member. If any value is queued to the selected signal, return the first queued value in the si_value member. If no signal in set is pending, suspend the calling thread until one or more become pending. If the time interval specified by timeout passes, sigtimedwait will return with the error EAGAIN. This function returns the signal number—on error, it returns -1 and sets errno to the appropriate error code.

References: 6.6.4 Headers: <signal.h>

Errors: [EINVAL] set contains an invalid signal number.

[EAGAIN] the timeout interval passed.

[ENOSYS] realtime signals are not supported. Hint: Use only for asynchronous signal delivery. All signals in set must

be masked in the calling thread, and should usually be masked in

all threads.

sigwait

int sigwait (

const sigset_t *set, int *sig);

If a signal in set is pending, atomically clear it from the set of pending signals and return the signal number in the location referenced by sig. If no signal in set is pending, suspend the calling thread until one or more become pending.

References: 6.6.4 Headers: <signal.h>

Errors: [EINVAL] set contains an invalid signal number.

Hint: Use only for asynchronous signal delivery. All signals in set must

be masked in the calling thread, and should usually be masked in

all threads.

sigwaitinfo

int sigwaitinfo (

const sigset_t *set, siginfo_t *info);

If a signal in set is pending, atomically clear it from the set of pending signals and return the signal number in the si_signo member of info. The cause of the signal shall be stored in the si_code member. If any value is queued to the selected signal, return the first queued value in the si_value member. If no signal in set is pending, suspend the calling thread until one or more become pending. This function returns the signal number—on error, it returns -1 and sets errno to the appropriate error code.

References: 6.6.4 Headers: <signal.h>

Errors: [EINVAL] set contains an invalid signal number.

[ENOSYS] realtime signals are not supported. Hint: Use only for asynchronous signal delivery. All signals in set must

be masked in the calling thread, and should usually be masked in

all threads.

Оглавление книги


Генерация: 0.077. Запросов К БД/Cache: 0 / 2
поделиться
Вверх Вниз