293 lines
8.8 KiB
HTML
293 lines
8.8 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_setpthreadoption_np()--Set 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_setpthreadoption_np()--Set Pthread Run-Time Option Data</h2>
|
||
|
|
||
|
<div class="box" style="width: 70%;">
|
||
|
<br>
|
||
|
Syntax:
|
||
|
|
||
|
<pre>
|
||
|
#include <pthread.h>
|
||
|
int pthread_setpthreadoption_np(pthread_option_np_t *optionData);
|
||
|
</pre>
|
||
|
Service Program Name: QP0WTCBH<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Signal Safe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<p>The <strong>pthread_setpthreadoption_np</strong>() function sets option data
|
||
|
in the pthread run-time for the process.</p>
|
||
|
|
||
|
<p>Input data is specified 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, and the contents of the
|
||
|
<em>optionData</em> structure is not changed by the
|
||
|
<strong>pthread_setpthreadoption_np</strong>() function.</p>
|
||
|
|
||
|
<p>The currently supported options, the data they represent, and the valid
|
||
|
operations are as follows:</p>
|
||
|
|
||
|
<table border width="80%" cellpadding="5">
|
||
|
<tr>
|
||
|
<th valign="top"><em>option</em> field of the <em>option</em> parameter</th>
|
||
|
<th valign="top">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 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 set the current maximum
|
||
|
size of the allowed storage pool. The <em>optionValue</em> field of the
|
||
|
<em>optionData</em> parameter is used to set the current maximum number of
|
||
|
thread structures that will be allowed in the storage pool. By default, the
|
||
|
<em>optionValue</em> field must be a valid integer greater than or equal to
|
||
|
zero, or the <strong>EINVAL</strong> error is returned. The default 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">If the <em>option</em> field of the
|
||
|
<em>optionData</em> parameter is set to this option, the
|
||
|
<strong>EINVAL</strong> error is returned.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">
|
||
|
<strong>PTHREAD_OPTION_THREAD_CAPABLE_NP</strong></td>
|
||
|
<td align="left" valign="top">If the <em>option</em> field of the
|
||
|
<em>optionData</em> parameter is set to this option, the
|
||
|
<strong>EINVAL</strong> error is returned.</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 <<strong>pthread.h</strong>> header file. See <a href=
|
||
|
"rzah4hed.htm">Header files for Pthread functions</a>.<br><br></li>
|
||
|
|
||
|
<li><a href="users_20.htm">pthread_getpthreadoption_np()</a>--Get 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 <pthread.h>
|
||
|
#include <stdio.h>
|
||
|
#include "check.h"
|
||
|
|
||
|
#define NUMTHREADS 5
|
||
|
|
||
|
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[NUMTHREADS];
|
||
|
int rc=0;
|
||
|
int i=0;
|
||
|
pthread_option_np_t opt;
|
||
|
|
||
|
printf("Enter Testcase - %s\n", argv[0]);
|
||
|
|
||
|
printf("Create threads and prime the storage pool\n");
|
||
|
for (i=0; i<NUMTHREADS; ++i) {
|
||
|
rc = pthread_create(&thread[i], NULL, threadfunc, NULL);
|
||
|
checkResults("pthread_create(NULL)\n", rc);
|
||
|
}
|
||
|
|
||
|
printf("Joining all threads at once so thread n does not reuse\n"
|
||
|
"thread n-1's data structures\n");
|
||
|
for (i=0; i<NUMTHREADS; ++i) {
|
||
|
rc = pthread_join(thread[i], NULL);
|
||
|
checkResults("pthread_join()\n", rc);
|
||
|
}
|
||
|
|
||
|
showCurrentSizeOfPool();
|
||
|
|
||
|
/* Set the maximum size of the storage pool to 0. I.e. No reuse of */
|
||
|
/* pthread structures */
|
||
|
printf("Set the max size of the storage pool to 0\n");
|
||
|
memset(&opt, 0, sizeof(opt));
|
||
|
opt.option = PTHREAD_OPTION_POOL_NP;
|
||
|
opt.optionValue = 0;
|
||
|
rc = pthread_setpthreadoption_np(&opt);
|
||
|
checkResults("pthread_setpthreadoption_np()\n", rc);
|
||
|
|
||
|
printf("Create some more threads. Each thread structure will come\n"
|
||
|
"from the storage pool if it exists, but based on the max size of 0,\n"
|
||
|
"the thread structure will not be allowed to be reused\n");
|
||
|
for (i=0; i<NUMTHREADS; ++i) {
|
||
|
rc = pthread_create(&thread[i], NULL, threadfunc, NULL);
|
||
|
checkResults("pthread_create(NULL)\n", rc);
|
||
|
|
||
|
showCurrentSizeOfPool();
|
||
|
|
||
|
rc = pthread_join(thread[i], NULL);
|
||
|
checkResults("pthread_join()\n", rc);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
printf("Main completed\n");
|
||
|
return 0;
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Output:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
Enter Testcase - QP0WTEST/TPSEtopT
|
||
|
Create threads and prime the storage pool
|
||
|
Joining all threads at once so thread n does not reuse
|
||
|
thread n-1's data structures
|
||
|
Inside the thread
|
||
|
Inside the thread
|
||
|
Inside the thread
|
||
|
Inside the thread
|
||
|
Inside the thread
|
||
|
Current number of thread structures in pool is 5
|
||
|
|
||
|
Set the max size of the storage pool to 0
|
||
|
Create some more threads. Each thread structure will come
|
||
|
from the storage pool if it exists, but based on the max size of 0,
|
||
|
the thread structure will not be allowed to be reused
|
||
|
Current number of thread structures in pool is 4
|
||
|
Inside the thread
|
||
|
Current number of thread structures in pool is 3
|
||
|
Inside the thread
|
||
|
Current number of thread structures in pool is 2
|
||
|
Inside the thread
|
||
|
Current number of thread structures in pool is 1
|
||
|
Inside the thread
|
||
|
Current number of thread structures in pool is 0
|
||
|
Inside the thread
|
||
|
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>
|
||
|
|