[Prev] [Contents] [Next]

pthread_getpthreadoption_np()--Get Pthread Run-Time Option Data

Syntax

#include <pthread.h>
void pthread_getpthreadoption_np(pthread_option_np_t *optionData);
Threadsafe: Yes
Signal Safe: Yes

The pthread_getpthreadoption_np() function gets option data from the pthread run-time for the process.

Input and output data is specified and returned uniquely based on the specified optionData, see the table below for details on input and output. The option field in the optionData parameter is always required, other fields may be input, output or ignored based on the specific option used.

For all options, every reserved fields in the structure represented by optionData must be binary zero or the EINVAL error will be returned. Unless otherwise noted for an option, the target field in the option parameter is always ignored.

The currently supported options, the data they represent, and the valid operations are as follows:
option field of the option parameter Description
PTHREAD_OPTION_POOL_NP When a thread terminates and it is detached or joined to, certain data structures from the pthreads run-time are maintained in a pool for possible reuse by future threads. This allows a performance improvement for creating threads.Typically an application shouldn't be concerned with this storage pool. Use this option to determine what the current maximum size of the allowed storage pool is. The optionValue field of the optionData parameter will be set to the current maximum number of thread structures which will be maintained in the storage pool. By default, the maximum size of the storage reuse pool contains enough room for 512 thread structures.
PTHREAD_OPTION_POOL_CURRENT_NP When a thread terminates and it is detached or joined to, certain data structures from the pthreads run-time are maintained in a pool for possible reuse by future threads. This allows a performance improvement for creating threads. Typically an application shouldn't be concerned with this storage pool. Use this option to determine how many thread structures are currently in the storage pool. The optionValue field of the optionData parameter will be set to the current number of thread structures which are contained in the storage pool. By default, the storage pool contains no thread structures. When a thread terminates and is detached or joined to and the current size of the pool is less than the maximum size, the thread structure is added to the pool.
PTHREAD_OPTION_THREAD_CAPABLE_NP Not all OS/400 jobs are capable of starting threads at all times. Use this option to determine if thread creation is currently allowed for your process. The optionValue field of the optionData parameter will be set to indicate if thread creation is currently allowed. The field will be set to 0 to indicate thread creation is not allowed, the field will be set to 1 to indicate thread creation is allowed. If thread creation is not allowed, pthread_create() will fail with the EBUSY error. See pthread_create() for more details.

Parameters

option
(Input/Output) Address of the variable containing option information, and to contain output option information.

Authorities and Locks

None.

Return Value

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

Error Conditions

If pthread_getpthreadoption_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

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

void *threadfunc(void *parm)
{
  printf("Inside the thread\n");
  return NULL;
}

void showCurrentSizeOfPool(void)
{
  int                   rc;
  pthread_option_np_t   opt;

  memset(&opt, 0, sizeof(opt));
  opt.option = PTHREAD_OPTION_POOL_CURRENT_NP;
  rc = pthread_getpthreadoption_np(&opt);
  checkResults("pthread_getpthreadoption_np()\n", rc);

  printf("Current number of thread structures in pool is %d\n",
         opt.optionValue);
  return;
}

int main(int argc, char **argv)
{
  pthread_t             thread;
  int                   rc=0;
  pthread_option_np_t   opt;

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

  printf("Create thread using the NULL attributes\n");
  rc = pthread_create(&thread, NULL, threadfunc, NULL);
  checkResults("pthread_create(NULL)\n", rc);

  memset(&opt, 0, sizeof(opt));
  opt.option = PTHREAD_OPTION_POOL_NP;
  rc = pthread_getpthreadoption_np(&opt);
  checkResults("pthread_getpthreadoption_np()\n", rc);

  printf("Current maximum pool size is %d thread structures\n",
         opt.optionValue);

  showCurrentSizeOfPool();

  printf("Joining to the thread may it to the storage pool\n");
  rc = pthread_join(thread, NULL);
  checkResults("pthread_join()\n", rc);

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

Output

Enter Testcase - QP0WTEST/TPGETOPT
Create thread using the NULL attributes
Current maximum pool size is 512 thread structures
Current number of thread structures in pool is 0
Joining to the thread may it to the storage pool
Inside the thread
Current number of thread structures in pool is 1
Main completed




[Prev] [Contents] [Next]
Copyright © 1998, IBM Corporation. All rights reserved.
Comments? Contact
rchthrds@us.ibm.com