[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


pthread_mutex_trylock

Tries to lock a mutex. If the mutex is already locked, the calling thread does not wait for the mutex to become available.

Syntax

pthread_mutex_trylock(
                      mutex );
 


Argument Data Type Access

mutex opaque pthread_mutex_t read


C Binding

#include 

int pthread_mutex_trylock ( pthread_mutex_t *mutex);

Arguments

mutex
Mutex to be locked.

Description

This routine tries to lock a mutex. When a thread calls this routine, an attempt is made to immediately lock the mutex. If the mutex is successfully locked, 0 is returned and the current thread is then the mutex's current owner. If the specified mutex is locked when a thread calls this routine, the calling thread does not wait for the mutex to become available.

The behavior of this routine is as follows:

Use the pthread_mutexattr_settype_np routine to set the mutex type attribute (normal, recursive, or errorcheck). For information about mutex types and their usage, see Chapter 2.

Return Values

If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return        Description

0 Successful completion. [EBUSY] The mutex is already locked; therefore, it was not acquired. [EINVAL] The value specified by mutex is invalid, or The mutex was created with the protocol attribute set to PTHREAD_PRIO_PROTECT and the calling thread's priority set higher than the mutex's current priority ceiling.


Associated Routines

   pthread_mutexattr_settype_np
   pthread_mutex_destroy
   pthread_mutex_init
   pthread_mutex_lock
   pthread_mutex_unlock



[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]