ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/users_20.htm

262 lines
8.2 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>pthread_getpthreadoption_np()--Get Pthread Run-Time Option Data</title>
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Begin Header Records ========================================== -->
<!-- NETMG2 SCRIPT A converted by B2H R4.1 (346) (CMS) by HOLTJM at -->
<!-- RCHVMW2 on 29 Jan 1999 at 10:01:37 -->
<!--File Edited November 2001 -->
<!--End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- Java sync-link -->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<a name="Top_Of_Page"></a>
<h2>pthread_getpthreadoption_np()--Get Pthread Run-Time Option Data</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax:
<pre>
#include &lt;pthread.h&gt;
int pthread_getpthreadoption_np(pthread_option_np_t *optionData);
</pre>
&nbsp;&nbsp;Service Program Name: QP0WTCBH<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Signal Safe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>pthread_getpthreadoption_np</strong>() function gets option data
from the pthread run-time for the process.</p>
<p>Input and output data is specified and returned uniquely based on the
specified <em>optionData</em>. See the table below for details about input and
output. The option field in the <em>optionData</em> parameter is always
required. Other fields may be input, output, or ignored, based on the specific
option used.</p>
<p>For all options, every reserved field in the structure represented by
<em>optionData</em> must be binary zero or the <strong>EINVAL</strong> error is
returned. Unless otherwise noted for an option, the <em>target</em> field in
the <em>option</em> parameter is always ignored.</p>
<p>The currently supported options, the data they represent, and the valid
operations are as follows:</p>
<table border="1" width="80%" cellpadding="5">
<tr>
<th><em>option</em> field of the <em>option</em> parameter</th>
<th>Description</th>
</tr>
<tr>
<td align="left" valign="top" width="50%">
<strong>PTHREAD_OPTION_POOL_NP</strong></td>
<td align="left" valign="top" width="50%">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 improves
performance for creating threads. Typically, an application should not be
concerned with this storage pool. Use this option to determine what the current
maximum size of the allowed storage pool is. The <em>optionValue</em> field of
the <em>optionData</em> parameter is set to the current maximum number of
thread structures, which is maintained in the storage pool. By default, the
maximum size of the storage reuse pool contains enough room for 512 thread
structures.</td>
</tr>
<tr>
<td align="left" valign="top">
<strong>PTHREAD_OPTION_POOL_CURRENT_NP</strong></td>
<td align="left" valign="top">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 improves performance for
creating threads. Typically, an application should not be concerned with this
storage pool. Use this option to determine how many thread structures are
currently in the storage pool. The <em>optionValue</em> field of the
<em>optionData</em> parameter is 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.</td>
</tr>
<tr>
<td align="left" valign="top">
<strong>PTHREAD_OPTION_THREAD_CAPABLE_NP</strong></td>
<td align="left" valign="top">Not all i5/OS jobs can start threads at all
times. Use this option to determine whether thread creation is currently
allowed for your process. The <em>optionValue</em> field of the
<em>optionData</em> parameter is set to indicate whether thread creation is
currently allowed. The field is set to 0 to indicate that 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() fails with the EBUSY error.
See pthread_create() for more details.</td>
</tr>
</table>
<br>
<br>
<h3>Authorities and Locks</h3>
<p>None.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>option</strong></dt>
<dd>(Input/Output) Address of the variable containing option information and to
contain output option information.</dd>
</dl>
<br>
<h3>Return Value</h3>
<dl>
<dt><strong>0</strong></dt>
<dd><strong>pthread_getpthreadoption_np</strong>() was successful.<br><br></dd>
<dt><strong>value</strong></dt>
<dd><strong>pthread_getpthreadoption_np</strong>() was not successful.
<em>value</em> is set to indicate the error condition.</dd>
</dl>
<br>
<h3>Error Conditions</h3>
<p>If <strong>pthread_getpthreadoption_np</strong>() 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.</p>
<dl>
<dt><em>[EINVAL]</em></dt>
<dd><p>The value specified for the argument is not correct.</p></dd>
</dl>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>pthread.h</strong>&gt; header file. See <a href=
"rzah4hed.htm">Header files for Pthread functions</a>.<br><br></li>
<li><a href="users_30.htm">pthread_setpthreadoption_np()</a>--Set Pthread Run-Time
Option Data</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<pre>
#define _MULTI_THREADED
#include &lt;pthread.h&gt;
#include &lt;stdio.h&gt;
#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(&amp;opt, 0, sizeof(opt));
opt.option = PTHREAD_OPTION_POOL_CURRENT_NP;
rc = pthread_getpthreadoption_np(&amp;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(&amp;thread, NULL, threadfunc, NULL);
checkResults("pthread_create(NULL)\n", rc);
memset(&amp;opt, 0, sizeof(opt));
opt.option = PTHREAD_OPTION_POOL_NP;
rc = pthread_getpthreadoption_np(&amp;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;
}
</pre>
<p><strong>Output:</strong></p>
<pre>
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
</pre>
<br>
<hr>API introduced: V4R3
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"rzah4mst.htm">Pthread APIs</a> | <a href="aplist.htm">APIs by
category</a></td>
</tr>
</table>
</center>
</body>
</html>