pthread_mutexattr_getkind_np()--Get Mutex Kind Attribute


  Syntax:
 #include <pthread.h>
 int pthread_mutexattr_getkind_np(const pthread_mutexattr_t *attr,  
 			   	  int *kind);
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_mutexattr_getkind_np() function retrieves the kind attribute from the mutex attributes object specified by attr. The mutex kind attribute is used to create mutexes with different behaviors.

The kind returned is one of PTHREAD_MUTEX_NONRECURSIVE_NP or PTHREAD_MUTEX_RECURSIVE_NP.

A recursive mutex can be locked repeatedly by the owner. The mutex does not become unlocked until the owner has called pthread_mutex_unlock() for each successful lock request that it has outstanding on the mutes.

Note: This function is not portable.


Authorities and Locks

None.


Parameters

attr
(Input) Address of the mutex attributes object
kind
(Output) Address of the variable to receive the kind attribute

Return Value

0
pthread_mutexattr_getkind_np() was successful.
value
pthread_mutexattr_getkind_np() was not successful. value is set to indicate the error condition.

Error Conditions

If pthread_mutexattr_getkind_np() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.

[EINVAL]

The value specified for the argument is not correct.


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

#include <pthread.h>
#include <stdio.h>
#include "check.h"

void showKind(pthread_mutexattr_t *mta) {
  int           rc;
  int           kind;

  printf("Check kind attribute\n");
  rc = pthread_mutexattr_getkind_np(mta, &kind);
  checkResults("pthread_mutexattr_getpshared()\n", rc);

  printf("The pshared attributed is: ");
  switch (kind) {
  case PTHREAD_MUTEX_NONRECURSIVE_NP:
    printf("PTHREAD_MUTEX_NONRECURSIVE_NP\n");
    break;
  case PTHREAD_MUTEX_RECURSIVE_NP:
    printf("PTHREAD_MUTEX_RECURSIVE_NP\n");
    break;
  default :
    printf("! kind Error kind=%d !\n", kind);
    exit(1);
  }
  return;
}

int main(int argc, char **argv)
{
  int                   rc=0;
  pthread_mutexattr_t   mta;
  int                   pshared=0;

  printf("Enter Testcase - %s\n", argv[0]);

  printf("Create a default mutex attribute\n");
  rc = pthread_mutexattr_init(&mta);
  checkResults("pthread_mutexattr_init()\n", rc);
  showKind(&mta);

  printf("Change mutex kind attribute\n");
  rc = pthread_mutexattr_setkind_np(&mta, PTHREAD_MUTEX_RECURSIVE_NP);
  checkResults("pthread_mutexattr_setkind()\n", rc);
  showKind(&mta);

  printf("Destroy mutex attribute\n");
  rc = pthread_mutexattr_destroy(&mta);
  checkResults("pthread_mutexattr_destroy()\n", rc);

  printf("Main completed\n");
  return 0;
}

Output:

Enter Testcase - QP0WTEST/TPMTXAKN0
Create a default mutex attribute
Check kind attribute
The pshared attributed is:
PTHREAD_MUTEX_NONRECURSIVE_NP
Change mutex kind attribute
Check kind attribute
The pshared attributed is:
PTHREAD_MUTEX_RECURSIVE_NP
Destroy mutex attribute
Main completed

API introduced: V4R3
Top | Pthread APIs | APIs by category