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

123 lines
4.3 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>Information on the Pthread API examples</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>Information on the Pthread API examples</h2>
<p>The API documentation includes example programs for each API. The
<a href="#326794">header file</a> shown below is used for all of the examples.
It should be named <strong>check.h</strong> (member <strong>CHECK</strong> in
file <strong>H</strong> in a library in the library list).</p>
<p>In most cases, error checking that is contained in the examples causes the
program to exit() if any failure is detected. In some cases, error checking is
left out of the examples for brevity. In general, the error checking that is
provided should not be considered complete enough for all applications. All
return codes from any system functions should be validated and appropriate
action should be taken when failures occur.</p>
<p>The examples are provided "as-is" for demonstration and education purposes
only. They do not necessarily provide or implement an appropriate level of
error checking to be used for production code and should not be used directly
for that purpose.</p>
<p>Be sure to see <a href="concept1.htm">Writing and compiling threaded
programs</a> and <a href="293735.htm">Running threaded programs</a> for more
information about compiling and running the example programs.</p>
<p>To create the examples, make sure the member <strong>CHECK</strong> is
created in a file <strong>H</strong> in your library list. Use <strong>
CRTCMOD</strong> on the name that you download the member to, then use <strong>
CRTPGM</strong> to link the module into a program object. Alternatively, you
can use <strong>CRTBNDC</strong> to compile and link the program in one
step.</p>
<p>When you run the example programs, you must be aware of a requirement:</p>
<p>The job that runs a threaded program must be specially initialized by the
system to support threads. Currently, several mechanisms allow you to start a
job that is capable of creating multiple kernel threads.</p>
<ul>
<li>Use the i5/OS QShell Interpreter</li>
<li>Use the spawn() API.</li>
<li>Use the SMJOB CL command.</li>
<li>Use the CRTJOBD CL command to create a special job description, then create
your job using a mechanism that will use the job description.</li>
</ul>
<p>See <a href="293735.htm">Running threaded programs</a> for detailed
information on these methods.</p>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<br>
<h3><a name="326794">File check.h used by API examples programs</a></h3>
<p>This example header file must be in the library list when you compile the
example programs.</p>
<pre>
#ifndef _CHECK_H
#define _CHECK_H
/* headers used by a majority of the example program */
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;errno.h&gt;
/* Simple function to check the return code and exit the program
if the function call failed
*/
static void checkResults(char *string, int rc) {
if (rc) {
printf("Error on : %s, rc=%d",
string, rc);
exit(EXIT_FAILURE);
}
return;
}
#endif
</pre>
<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>