IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Resolving deadlock in CICS


IBM Mainframe Forums -> CICS
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ramvivek

New User


Joined: 23 Oct 2006
Posts: 13

PostPosted: Wed Aug 08, 2007 1:39 pm
Reply with quote

Hi,

I have a deadlock problem in CICS. Two files are being read with update option in two diff pgms. So I am running into a deadlock situation.Is there any way to handle this ?

Thanks,
Ramkumar M.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Wed Aug 08, 2007 8:50 pm
Reply with quote

yes, review EXEC CICS ENQ and EXEC CICS DEQ commands,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 09, 2007 12:19 am
Reply with quote

Hello,

You may need to change one of the programs so that locking will be in the same order as the "other" program. This may cause things to slow down, but will prevent the deadlock.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Thu Aug 09, 2007 12:50 am
Reply with quote

enq
read update
rewrite
deq

is the normal suggested method to prevent deadlock's
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 09, 2007 2:52 am
Reply with quote

Hello,

If there is a separate enq/deq placed around each of the updates (2 different files), will there still not be a deadlock?

Is the enq mechanism "smart enough" to abend the transaction that issues the 4th enq that would cause the deadlock?
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Thu Aug 09, 2007 3:32 am
Reply with quote

only 1 enq / deq for multiple files, use in both of the problem programs.

ENQ
read file ('file1') update
rewrite
read file ('file2') update
rewrite
read file ('file3') update
rewrite
read file ('file4') update
rewrite
DEQ

normally for deadlock, different tasks trying to update the same file and program logic is performing other long running process in between EXEC CICS UPDATE and EXEC CICS REWRITE.

enq/deq will force program logic in both programs to in effect' go single thread, first come, first service.

1st task that enq's on a resource owns it, and any other task that enq's on the same resource will wait until the resource has been deq'd.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Thu Aug 09, 2007 3:36 am
Reply with quote

can you explain logic of problem programs a little more.

you should be able to update the same file with 2 different programs, without using enq/deq.

the deadlock could be caused from some other logic problem .

is either of the programs trying to read or browse the same file in between the
exec cics read update
and
exec cics rewrite

???
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 09, 2007 3:36 am
Reply with quote

Can't remember, but does not VSAM provide a return which can be interpreted as a deadlock situation?

In DB2, if a task receives notification of timeout or deadlock, we do a rollback to allow the other task to complete, WAIT a few seconds then RESTART the Unit of Work. Yeah, I know, gotta keep track, so you can restart. AND these are not two instances of the same program.

If multiple instances of the same program are causing deadlocks, you have a design problem.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Thu Aug 09, 2007 3:45 am
Reply with quote

no return code from vsam (that I know of , indicating deadlock).
DINO, is correct, could be some design issues here.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 09, 2007 5:40 am
Reply with quote

Hello,

Yes, one issue is that one program reads file1 for update and the other reads file2 for update (at pretty much the same time). Then program1 tries to read what program2 has already read for update. Finally (again, at the same time) program2 needs to read what program1 has already "locked" - hence the deadlock (or deadly embrace). All good database systems terminate the last process that would have completed the ermbrace. With vsam, they lock.

As Earl has mentioned, all of the processing could be serialized, but the backup in the processes may not be acceptable.

If one or the other program was changed to lock in the same order as the other, it would be a degredation, but hopefully, not as severe as completely single-threading.
Back to top
View user's profile Send private message
Earl

Active User


Joined: 17 Jun 2007
Posts: 148
Location: oklahoma

PostPosted: Thu Aug 09, 2007 6:33 am
Reply with quote

no wonder there is deadlock.


read for update puts an exclusive hold on the record until
exec cics rewrite
exec cics delete
exec cics release
or
task ends (normally or abnormally)

which is why IBM
recommends:
the only thing that should logically follow a "read for update"
is moving the changed record to the buffer,
and
then exec cics rewrite.

looks like a design problem, put in extra reads (without read for update).
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CICS

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Calling an Open C library function in... CICS 1
No new posts How to 'Ping' a CICS region in JCL CICS 2
No new posts Parallelization in CICS to reduce res... CICS 4
No new posts How to avoid duplicating a CICS Web S... CICS 0
Search our Forums:

Back to Top