Name

pthread_mutex_lock
- lock a mutex

Library

libc_r.lib libpthread.lib libthr.lib

Synopsis

  #include <pthread.h>
  int pthread_mutex_lock (pthread_mutex_t *mutex);

Return values

If successful, pthread_mutex_lock will return zero, otherwise an error number will be returned to indicate the error.

Detailed description

The pthread_mutex_lock function locks mutex. If the mutex is already locked, the calling thread will block until the mutex becomes available.

Examples

pthread_mutex_t  mutex;
int XYZ()
{
 int rc;
 /* Initialize a mutex object with the default mutex attributes */
 if((rc=pthread_mutex_init(&mutex,NULL)) != 0) {
  fprintf(stderr,"Error at pthread_mutex_init(), rc=%d\n",rc);
  return -1;
 }
 /* Lock the mutex using pthread_mutex_lock() */
 if((rc=pthread_mutex_lock(&mutex)) == 0) {
  printf(" lock is successful\n");
 }
}

         

Errors

The pthread_mutex_lock function will fail if:
[ENOSYS]
  If locking is not supported for this mutex kind.
[ETIMEDOUT]
  Mutex wait is timed out.
[EINVAL]
  The value specified by mutex is invalid.
[EDEADLK]
  A deadlock would occur if the thread blocked waiting for mutex.

See also

pthread_mutex_destroy, pthread_mutex_init, pthread_mutex_trylock, pthread_mutex_unlock
The pthread_mutex_lock function conforms to -p1003.1-96.

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top