Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 10: CICS Transaction Processing


ENQ and DEQ

EXEC CICS ENQ gives your task exclusive control of a named resource; EXEC CICS DEQ releases it.

They serialize access to anything CICS does not lock for you, like a shared counter or a common work area.

What ENQ does

  • ENQ RESOURCE(name) locks a logical resource for this task alone.
  • If another task holds the resource, your task waits - unless NOSUSPEND is coded.
  • LENGTH tells CICS how many bytes of the name identify the resource.
  • Without LENGTH, CICS enqueues on the storage address itself, so always code LENGTH with a name.

Using DEQ

  • DEQ RESOURCE(name) releases a lock your task holds.
  • Release locks as soon as the critical section is done; do not wait for task end.
  • All enqueues are released automatically at syncpoint or at task end.
  • The RESOURCE and LENGTH on DEQ must match the ENQ exactly.

Deadlock

  • Deadlock happens when two tasks each wait for a resource that the other one holds.
  • Neither task can proceed, so both hang until one of them is purged.
  • Prevent it by always locking resources in the same order in every program.
  • Keep the locked section short so waits are rare and brief.

Example of ENQ and DEQ

  • Lock the shared counter, update it, and release it immediately.
  • *--- lock the shared counter, update it, release it --- EXEC CICS ENQ RESOURCE('ORDER-COUNTER') LENGTH(13) END-EXEC. ADD 1 TO WS-ORDER-COUNTER. EXEC CICS DEQ RESOURCE('ORDER-COUNTER') LENGTH(13) END-EXEC.
  • The LENGTH of 13 matches the 13 characters in 'ORDER-COUNTER'.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant