27.04.2013 Views

MVS Jan 2005.p65 - CBT Tape

MVS Jan 2005.p65 - CBT Tape

MVS Jan 2005.p65 - CBT Tape

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Multi-tasking with IBM C/C++ programs<br />

Inter- and intra-address space multi-tasking is a very powerful<br />

capability providing one of the very basic tools associated with<br />

<strong>MVS</strong> and all its successor operating systems. Multiple code<br />

paths can be active simultaneously either within the same<br />

address space or in secondary address spaces, allowing for<br />

very complex application support. This capability extends to<br />

programs written in IBM C/C++ and a number of techniques<br />

are inherently available for this purpose.<br />

INHERENT MULTI-TASKING TECHNIQUES<br />

Several techniques are available for employing multi-tasking<br />

functionality in IBM C/C++. Let’s discuss the more common<br />

techniques – fork(), spawn(), pthread_create(), and the C<br />

Multi-Tasking Facility (MTF).<br />

THE FORK() FUNCTION<br />

One of the classic multi-tasking tools in C/C++ is the fork()<br />

function call. The fork() function performs as follows.<br />

The issuer of the fork() function (the parent process) creates<br />

a new unit of work (the child process) that, for all intents and<br />

purposes, is a clone of the parent. Execution in both the parent<br />

and the child process continues from the point immediately<br />

following the fork() function call. To determine whether this is<br />

a parent or a child process, a simple check of the return code<br />

from fork() can be made. If the return code is less than 0, the<br />

fork() function call has failed and the errno variable can be<br />

examined to obtain additional information regarding the failure.<br />

If the return code is greater than 0, program execution is in the<br />

parent process and the return code value from the fork()<br />

function call is the process id (PID) of the created child<br />

process. If the return code is equal to 0, program execution is<br />

in the child process. Programmatically, this could look<br />

© 2005. Reproduction prohibited. Please inform Xephon of any infringement.<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!