Anteprima
Vedrai una selezione di 1 pagina su 3
Sistemi operativi - Syscall pthread_cond_wait Pag. 1
1 su 3
D/illustrazione/soddisfatti o rimborsati
Disdici quando
vuoi
Acquista con carta
o PayPal
Scarica i documenti
tutte le volte che vuoi
Estratto del documento

pthread_cond_wait, pthread_cond_timedwait - wait on a condition

The Single UNIX ® Specification, Version 2

Copyright © 1997 The Open Group

NAME

pthread_cond_wait, pthread_cond_timedwait - wait on a condition

SYNOPSIS

#include <pthread.h>
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond,pthread_mutex_t *mutex, const struct timespec *abstime);

DESCRIPTION

The pthread_cond_wait() and pthread_cond_timedwait() functions are used to block on a condition variable. They are called with mutex locked by the calling thread or undefined behaviour will result.

These functions atomically release mutex and cause the calling thread to block on the condition variable cond; atomically here means "atomically with respect to access by another thread to the mutex and then the condition variable". That is, if another thread is able to acquire the mutex after the about-to-block thread has released it, then a

subsequent call topthread_cond_signal() or pthread_cond_broadcast() in that thread behaves as if it were issued after the about-to-block thread has blocked.

Upon successful return, the mutex has been locked and is owned by the calling thread.

When using condition variables there is always a boolean predicate involving shared variables associated with each condition wait that is true if the thread should proceed. Spurious wakeups from the pthread_cond_wait() or pthread_cond_timedwait() functions may occur.

Since the return from pthread_cond_wait() or pthread_cond_timedwait() does not imply anything about the value of this predicate, the predicate should be re-evaluated upon such return.

The effect of using more than one mutex for concurrent pthread_cond_wait() or pthread_cond_timedwait() operations on the same condition variable is undefined; that is, a condition variable becomes bound to a unique mutex when a thread waits on the condition variable, and this (dynamic) binding ends when the wait.

A condition wait (whether timed or not) is a cancellation point. When the cancelability enablestate of a thread is set to PTHREAD_CANCEL_DEFERRED, a side effect of acting upon acancellation request while in a condition wait is that the mutex is (in effect) re-acquiredbefore calling the first cancellation cleanup handler. The effect is as if the thread wereunblocked, allowed to execute up to the point of returning from the call to pthread_cond_wait() or pthread_cond_timedwait(), but at that point notices the cancellationrequest and instead of returning to the caller of pthread_cond_wait() or pthread_cond_timedwait(), starts the thread cancellation activities, which includes callingcancellation cleanup handlers.

A thread that has been unblocked because it has been canceled while blocked in a call to...

Dettagli
Publisher
A.A. 2012-2013
3 pagine
SSD Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli studi di Napoli Federico II o del prof Cotroneo Domenico.