Chapter Contents

Previous

Next
ATTACH

ATTACH



Create a New Subtask

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTIONS
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <ostask.h>

int ATTACH(void **tcbaddr, ...);


DESCRIPTION

The ATTACH function implements the functionality of the OS/390 assembler ATTACH macro. The tcbaddr argument is the address of a void * area where the address of the new task control block (TCB) is to be stored. The remainder of the argument list is a list of keywords followed, in most cases, by an argument specifying a value for the keyword. The list is terminated by the _Aend keyword.

The supported keywords and their associated data are as follows:

The following should be noted about subtask termination. If neither an _Aecb nor _Aetxr keyword was specified, the subtask TCB is automatically detached when it terminates. Otherwise, the program is required to detach the TCB itself after the subtask has terminated. (Refer to the DETACH macro later in this chapter.)

If a C program terminates normally with active subtasks created by the ATTACH function, the library detaches these subtasks automatically. If a subtask has terminated, the library assumes that the program has detached it. If this assumption is untrue, the program will be abnormally terminated by the operating system.

If an active subtask is detached by the program using the C DETACH macro, an ETXR routine is not called. Also, ETXR routines are not called for tasks detached by the library during normal program termination.


RETURN VALUE

ATTACH returns 0 if the ATTACH macro was successful. If the ATTACH macro fails, it returns the return code from the macro, which will be a positive value. ATTACH may also return -1 to indicate an unknown keyword, or -2 if there was not enough memory to do the attach.


CAUTIONS

In general, the _Aparam keyword should always be specified. See the discussion of this keyword under "DESCRIPTION."

You should be wary of defining subtask parameters in automatic storage, unless the calling function waits for the subtask to complete. Otherwise, the storage for the parameters could be freed or reused while the subtask is accessing them.


IMPLEMENTATION

The ATTACH function is implemented by the source module L$UATTA. The SPE implementation of ETXR exits is provided by the source module L$UAEOT.


EXAMPLE

This example attaches the SAS/C Compiler out of the DDname SASCLIB, and uses the WAIT1 function to wait for it to complete.

#include <ostask.h>
#include <stdio.h>
#include <osio.h>

DCB_t *tasklib;
unsigned myecb;
int rc;
void *subtcb;
void *plist [1]  ;                     /* parm list for compiler     */
struct {
   short len;
   char options[8];
} argument = {8, "OPTIMIZE"};

tasklib = osdcb("SASCLIB", "DSORG=PO", NULL, 0);
if (!tasklib) abort();
if (osbopen(tasklib, "input")) abort();
myecb = 0;                           /* Initialize ECB.            */
plist [  0]   = (void *)(0x80000000 | (unsigned) &  argument);
   /* Set up compiler parm list.                                   */
rc = ATTACH(&subtcb, _Aep, "LC370B", _Atasklib, tasklib, _Aecb,
            &myecb, _Aparam, plist, _Aend);
if (rc != 0) abort();             /* if the ATTACH failed          */
WAIT1(&  myecb);                  /* Wait for compiler to complete.*/
DETACH(&  subtcb,NOSTAE);         /* Detach the TCB.               */
printf("Compiler return code %d\n",
        /* Display compiler return code.                           */
        myecb &   0x3fffffff);
osbclose(tasklib, "disp", 1);


RELATED FUNCTIONS

DETACH , oslink , system


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.