pthread_rwlockattr_destroy()--Destroy Read/Write Lock Attribute


  Syntax:
 #include <pthread.h>
 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);   
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

The pthread_rwlockattr_destroy() function destroys a read/write lock attributes object and allows the systems to reclaim any resources associated with that read/write lock attributes object. This does not have an effect on any read/write lock already created using this read/write lock attributes object.


Authorities and Locks

None.


Parameters

attr
(Input) Address of the read/write lock attributes object to be destroyed

Return Value

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

Error Conditions

If pthread_rwlockattr_destroy() 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

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

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

pthread_rwlock_t        rwlock1;
pthread_rwlock_t        rwlock2 = PTHREAD_RWLOCK_INITIALIZER;

int main(int argc, char **argv)
{
  int                   rc=0;
  pthread_rwlockattr_t  attr;

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

  printf("Create a default rwlock attribute\n");
  rc = pthread_rwlockattr_init(&attr);
  checkResults("pthread_rwlockattr_init()\n", rc);

  printf("Use the rwlock attributes to created rwlocks here\n");
  rc = pthread_rwlock_init(&rwlock1, &attr);
  checkResults("pthread_rwlock_init()\n", rc);

  printf("The rwlock1 is now ready for use.\n");
  printf("The rwlock2 that was statically initialized was ready when\n"
         "the main routine was entered\n");

  printf("Destroy rwlock attribute\n");
  rc = pthread_rwlockattr_destroy(&attr);
  checkResults("pthread_rwlockattr_destroy()\n", rc);

  printf("Use the rwlocks\n");
  rc = pthread_rwlock_rdlock(&rwlock1);
  checkResults("pthread_rwlock_rdlock()\n", rc);

  rc = pthread_rwlock_wrlock(&rwlock2);
  checkResults("pthread_rwlock_wrlock()\n", rc);

  rc = pthread_rwlock_unlock(&rwlock1);
  checkResults("pthread_rwlock_unlock(1)\n", rc);

  rc = pthread_rwlock_unlock(&rwlock2);
  checkResults("pthread_rwlock_unlock(2)\n", rc);

  printf("Destroy the rwlocks\n");
  rc = pthread_rwlock_destroy(&rwlock1);
  checkResults("pthread_rwlock_destroy(1)\n", rc);

  rc = pthread_rwlock_destroy(&rwlock2);
  esults("pthread_rwlock_destroy(2)\n", rc);

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

Output:

Enter Testcase - QP0WTEST/TPRWLAI0
Create a default rwlock attribute
Use the rwlock attributes to created rwlocks here
The rwlock is now ready for use.
The rwlock that was statically initialized was ready when
the main routine was entered
Destroy rwlock attribute
Use the rwlocks
Destroy the rwlocks
Main completed


API introduced: V4R3

[ Back to top | Pthread APIs | APIs by category ]