ATTACHX problem: task doesn't terminate after termination of main program 
Author Message
 ATTACHX problem: task doesn't terminate after termination of main program

Hi NG,

I apologize in advance for that long message, but I almost have lost all of my hair trying to solve this problem.

If I call subroutines using ATTACHX the task doesn't terminate after termination of the main program.

The main program ATTCH0
  . opens SYSOUT,
  . writes some information lines
  . ATTACHXes subroutines ATTACH1 and ATTACH2 which write some lines to SYSOUT, too
  . waits untils subroutine ATTACH1 and ATTACH2 have ended.
    To do this the address of an end flag is given to the subroutine.
    At end of subroutine ATTACH1 and ATTACH2 the end flag is set to "X" and the subroutine terminates.
  . when both end flags are set, ATTACH0 writes an end message to SYSOUT
    ("ATTACH0 ENDED") and terminates.

The subroutine ATTACH1 (and ATTACH2)
  . writes a START message to SYSOUT
  . writes out 4 lines to SYSOUT
  . sets the end flag (whichs address was given as parameter to the subroutine)
  . terminates

The problem is, that the task continues to process after the main program has terminated!
If I comment out the ATTACHX lines in ATTACH0 the task stops immediately after termination of ATTACH0.

Any help appreciated!

Thanks in advance,
Gerd

The job:

//*                                                
//JOBLIB   DD  DSN=TISS.GTR.PCI.LOADLIB,DISP=SHR  
//*                                                
//*------------------------------------------------
//ATTACH  EXEC PGM=ATTACH0                        
//*------------------------------------------------
//SYSOUT   DD  SYSOUT=*,RECFM=FB,LRECL=132        
//*                                                

The job output in SYSOUT (as expected):

  SDSF BROWSE  G171GGBA (JOB06890) SYSOUT              
  Command ===>                                        
 ********************************* Top of Data ********
 ATTACH0 STARTED                                      
 STARTING ATTACH1...                                  
 STARTING ATTACH2...                                  
 ATTACH1 STARTED                                      
 ATTACH1: LINE 1                                      
 ATTACH1: LINE 2                                      
 ATTACH1: LINE 3                                      
 ATTACH1: LINE 4                                      
 ATTACH1 ENDED                                        
 ATTACH2 STARTED                                      
 ATTACH2: LINE 1                                      
 ATTACH2: LINE 2                                      
 ATTACH2: LINE 3                                      
 ATTACH2: LINE 4                                      
 ATTACH2 ENDED                                        
 ATTACH0 ENDED                                        
 ******************************** Bottom of Data ******                                                      

The main program (ATTACH0):

 ATTACH0  START                                                          

          STM   14,12,12(13)                     save register          

          BALR  2,0                              set base register      
          USING *,2                                                      

          OPEN  (SYSOUT,(OUTPUT))                                        

          MVC   IOAREA,SPACES                    print START message    
          MVC   IOAREA(15),=C'ATTACH0 STARTED'                          
          PUT   SYSOUT,IOAREA                                            

 *                                               print ATTACH message    
 *                                               for ATTACH1            
          MVC   IOAREA,SPACES                                            
          MVC   IOAREA(19),=C'STARTING ATTACH1...'                      
          PUT   SYSOUT,IOAREA                                            

          ATTACHX EP=ATTACH1,PARAM=(SYSOUT,SYNCFLAG,ENDFLAG1)            

 *                                               print ATTACH message    
 *                                               for ATTACH2            

 *                                               ATTACH1 and ATTACH2    
 *                                               print to SYSOUT so we  
 *                                               have to synchronise    
 *                                               all output operations  

          MVC   IOAREA,SPACES                                            
          MVC   IOAREA(19),=C'STARTING ATTACH2...'                      

          BAL   5,WAITFREE                       wait until SYSOUT free  
          PUT   SYSOUT,IOAREA                                            
          BAL   5,SETFREE                        reset SYNCFLAG          

          ATTACHX EP=ATTACH2,PARAM=(SYSOUT,SYNCFLAG,ENDFLAG2)            

 WAITEND  CLI   ENDFLAG1,C' '                    wait until ATTACH1 ends
          BE    WAITEND                                                  
          CLI   ENDFLAG2,C' '                    wait until ATTACH2 ends
          BE    WAITEND                                                  

          MVC   IOAREA,SPACES                    print END message      
          MVC   IOAREA(13),=C'ATTACH0 ENDED'                            
          PUT   SYSOUT,IOAREA                                            

          CLOSE SYSOUT                                                  

          LM    14,12,12(13)                     restore registers      
          SR    15,15                            reset return code      
          BR    14                               return                  

 WAITFREE CLI   SYNCFLAG,C' '                    wait until SYNCFLAG...  
          BNE   WAITFREE                         signals SYSOUT is free  
          MVI   SYNCFLAG,C'0'                    set SYNCFLAG            
          BR    5                                branch back            

 SETFREE  CLI   SYNCFLAG,C'0'                    SYNCFLAG still set ?    
          BNER  5                                no, return immediately  
          MVI   SYNCFLAG,C' '                    reset SYNCFLAG          
          BR    5                                branch back            

          LTORG                                                          

 SAVE13   DS    A                                save area R13          
 SAVEAREA DS    20F                              register save area      

 SYSOUT   DCB   DDNAME=SYSOUT,DSORG=PS,MACRF=PM                          

 IOAREA   DC    CL132' '                         IO area                
 SPACES   DC    CL132' '                                                

 SYNCFLAG DC    CL1' '                           output sync flag        
 ENDFLAG1 DC    CL1' '                           end flag for ATTACH1    
 ENDFLAG2 DC    CL1' '                           end flag for ATTACH2    

          END   ATTACH0                                                  

The ATTACHed subroutine 1 (ATTACH1):

 ATTACH1  START                                                          

          STM   14,12,12(13)                   save registers            

          BALR  2,0                            set base register        
          USING *,2                                                      

          L     6,0(1)                         load SYSOUT   address    
          L     7,4(1)                         load SYNCFLAG address    
          L     8,8(1)                         load ENDFLAG  address    

          USING SYSOUT,6                       base register SYSOUT      
          USING SYNCFLAG,7                     base register SYNCFLAG    
...

read more »



Fri, 09 Jan 2004 08:26:52 GMT  
 ATTACHX problem: task doesn't terminate after termination of main program

Instead of looping looking at a single byte repeatedly, you should
relinquish control occasionally by inserting this at places where you would
loop:

  CHAP 0,'S'

It tells the system you are giving up for the time being, but the next cycle
through it would be ok to dispatch the task again.

You will become quite hosed over (messed up) if the program is ever run on a
real multi-processor.



Hi NG,

I apologize in advance for that long message, but I almost have lost all of
my hair trying to solve this problem.

If I call subroutines using ATTACHX the task doesn't terminate after
termination of the main program.

The main program ATTCH0
 . opens SYSOUT,
 . writes some information lines
 . ATTACHXes subroutines ATTACH1 and ATTACH2 which write some lines to
SYSOUT, too
 . waits untils subroutine ATTACH1 and ATTACH2 have ended.
   To do this the address of an end flag is given to the subroutine.
   At end of subroutine ATTACH1 and ATTACH2 the end flag is set to "X" and
the subroutine terminates.
 . when both end flags are set, ATTACH0 writes an end message to SYSOUT
   ("ATTACH0 ENDED") and terminates.

The subroutine ATTACH1 (and ATTACH2)
 . writes a START message to SYSOUT
 . writes out 4 lines to SYSOUT
 . sets the end flag (whichs address was given as parameter to the
subroutine)
 . terminates

The problem is, that the task continues to process after the main program
has terminated!
If I comment out the ATTACHX lines in ATTACH0 the task stops immediately
after termination of ATTACH0.
(code snipped)



Fri, 09 Jan 2004 08:43:51 GMT  
 ATTACHX problem: task doesn't terminate after termination of main program


:>I apologize in advance for that long message, but I almost have lost all of my hair trying to solve this problem.

:>If I call subroutines using ATTACHX the task doesn't terminate after termination of the main program.

:>The main program ATTCH0
:>  . opens SYSOUT,
:>  . writes some information lines
:>  . ATTACHXes subroutines ATTACH1 and ATTACH2 which write some lines to SYSOUT, too
:>  . waits untils subroutine ATTACH1 and ATTACH2 have ended.
:>    To do this the address of an end flag is given to the subroutine.
:>    At end of subroutine ATTACH1 and ATTACH2 the end flag is set to "X" and the subroutine terminates.
:>  . when both end flags are set, ATTACH0 writes an end message to SYSOUT
:>    ("ATTACH0 ENDED") and terminates.

:>The subroutine ATTACH1 (and ATTACH2)
:>  . writes a START message to SYSOUT
:>  . writes out 4 lines to SYSOUT
:>  . sets the end flag (whichs address was given as parameter to the subroutine)
:>  . terminates

:>The problem is, that the task continues to process after the main program has terminated!
:>If I comment out the ATTACHX lines in ATTACH0 the task stops immediately after termination of ATTACH0.

Unless you are running on a uni-processor the tasks will run in parralell,
thus just because the flag is set does not mean that the task is complete.

The proper way to do what you want is to establish an ECB with your attach
which the system will post when the task completes (of course, if ECB or ETXR
are specified, an explicit DETACH must be issued). This will also save CPU as
your main task will not be burning cycles while waiting.

Also, be aware you synchronization code is not guaranteed to work. When two
processes are running, both could check the flag at the same time, both see it
free and both branch to the output routine. You must use an interlocked
instruction such as TS, CS, CDS or PLO (or serialize via ENQ) to avoid this
problem.

I suggest that you read up on multi-tasking considerations.

   [ program snipped ]

--


http://www.dissensoftware.com

Director, Dissen Software, Bar & Grill - Israel



Fri, 09 Jan 2004 16:01:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Deallocation of T'STORAGE_SIZE for a terminated task

2. Python20, tcl8.3.2 , IDLE 0.6, mainloop doesn't terminate

3. python20, tcl8.3.2, IDLE 0.6, mainloop doesn't terminate

4. hangs and Wish.exe doesn't terminate

5. Python process doesn't get terminated using Ctrl-C if site.py is being imported

6. InActivity Program Termination 'Template'

7. Builded executable doesn't close the main VI front panel

8. Main Window doesn't show up in my tk app

9. if __name__=='__main__': main()

10. tracing a program using __import__('__main__')?

11. Deployed app terminates after a MessageBox is displayed before main app shell view is opened

12. Program termination problem

 

 
Powered by phpBB® Forum Software