pthread_attr_setstacksize....................................................... [_POSIX_THREAD_ATTR_STACKSIZE]

int pthread_attr_setstacksize ( pthread_attr_t *attr, size_t stacksize);

Threads created with attr will run on a stack of at least stacksize bytes. Must be at least PTHREAD_STACK_MIN bytes.

References: 2, 5.2.3

<pthread.h>

[EINVAL] attr or stacksize invalid. [EINVAL] stacksize too small or too big. [ENOSYS] stacksize not supported.

Find the default first (pthread_attr_getstacksize), then increase by multiplying. Use only if a thread needs more than the default.

Headers: Errors:

Hint:

pthread_create

int pthread_create (

pthread_t *tid,

const pthread_attr_t *attr,

void *(*start) (void *),

void *arg);

Create a thread running the start function, essentially an asynchronous call to the function start with argument value arg. The attr argument specifies optional creation attributes, and the identification of the new thread is returned in tid.

References: 2, 5.2.3

Headers: <pthread.h>

Errors: [EINVAL] attr invalid.

[EAGAIN] insufficient resources. Hint: All resources needed by thread must already be initialized.

pthread_detach

int pthread_detach (

pthread_t thread);

Detach the thread. Use this to detach the main thread or to 'change your mind' after creating a joinable thread in which you are no longer interested.

References: 2, 5.2.3 Headers: <pthread.h>

Errors: [EINVAL] thread is not a joinable thread.

[ESRCH] no thread could be found for ID thread. Hint: Detached threads cannot be joined or canceled; storage is freed

immediately on termination.

pthread_equal

int pthread_equal (

pthread_t tl,

pthread_t t2);

Return value 0 if t1 and t2 are equal, otherwise return nonzero.

References: 2, 5.2.3 Headers: <pthread.h>

Hint: Compare pthread_self against stored thread identifier.

pthread_exit

int pthread_exit (

void *value_ptr);

Terminate the calling thread, returning the value value_ptr to any joining thread.

References: 2, 5.2.3 Headers: <pthread.h>

Hint: value ptr is treated as a value, not the address of a value.

pthread_join

int pthread_join (

pthread_t thread,

void **value_ptr);

Wait for thread to terminate, and return thread's exit value if value_ptr is not NULL. This also detaches thread on successful completion.

References: 2, 5.2.3 Headers: <pthread.h>

Errors: [EINVAL] thread is not a joinable thread.

[ESRCH] no thread could be found for ID thread.

[EDEADLK] attempt to join with self. Hint: Detached threads cannot be joined or canceled.

pthread_self

pthread_t pthread_self (void);

Return the calling thread's ID.

References: 2, 5.2.3 Headers: <pthread.h>

Hint: Use to set thread's scheduling parameters.

sched_yield

int sched_yield (void);

Make the calling thread ready, after other ready threads of the same priority, and select a new thread to run. This can allow cooperating threads of the same priority to share processor resources more equitably, especially on a uniprocessor. This function is from POSIX.1b (realtime extensions), and is declared in <sched.h>. It reports errors by setting the return value to - 1 and storing an error code in errno.

References: 2, 5.2.3 Headers: <sched.h>

Errors: [ENOSYS] sched_yield not supported.

Hint: Use before locking mutex to reduce chances of a timeslice while mu-

tex is locked.

9.3.4 Mutexes

Mutexes provide synchronization, the ability to control how threads share resources. You use mutexes to prevent multiple threads from modifying shared data at the same time, and to ensure that a thread can read consistent values for a set of resources (for example, memory) that may be modified by other threads.

pthread_mutexattr_destroy

int pthread_mutexattr_destroy (

pthread_mutexattr_t *attr);

Destroy a mutex attributes object. The object can no longer be used.

References: 3.2, 5.2.1

Headers: <pthread.h>

Errors: [EINVAL]attrinvalid.

Hint: Does not affect mutexes created using attr.

pthread_mutexattr_getpshared.............................................. [_POSIX_THREAD_PROCESS_SHARED]

int pthread_mutexattr_getpshared (

const pthread_mutexattr_t *attr,

int *pshared);

Determine whether mutexes created with attr can be shared by multiple processes.

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

0

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

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