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

Issuing DEQ before ENQ with same resource


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

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Nov 26, 2015 1:51 am
Reply with quote

I am testing a CICS transaction and in the program I am using ENQ / DEQ for serialized access.

Now, I am trying to see what happens if the resource is ENQueued by User1 and at the same time a DEQ is issued by User2 with same Resource name.
(I introduced a delay of 10 seconds after ENQ so that I can issue a DEQ when the resource is held)

I am using 2 terminals.

What is currently happening is that there is No effect of issuing DEQ with same resource. So, I start the transaction on terminal 1 and wait for 5 seconds and then start it on terminal 2. The transaction takes a little over 10 seconds on terminal 1 which is what it should be But on terminal 2 it takes a little over 15 seconds meaning the transaction at terminal 2 was waiting for transaction at terminal 1 to end i.e. it was queued.

But I had issued a DEQ command for the same resource before issuing ENQ then why it was queued. Please let me know your thoughts.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Thu Nov 26, 2015 3:11 am
Reply with quote

RahulG31,
Quote:
So, I start the transaction on terminal 1 and wait for 5 seconds and then start it on terminal 2
So after 5 seconds or little more the resource should get DEQ'ed from terminal 1 and next task sould begin at terminal 2.
Quote:
But on terminal 2 it takes a little over 15 seconds meaning the transaction at terminal 2 was waiting for transaction at terminal 1 to end i.e. it was queued.

I am not sure why was it taken 15 seconds or more as understood above it should only take 5+ seconds maximum, right? as term1 should finish by issuing DEQ.

So I think it works on a token just not same resources unless it finds the same token it wouldn't release the resource.

Code:
When issuing the DEQ command, the resource to be dequeued from must be identified by the method used when enqueuing on the resource. If no enqueue has been issued for the resource, the dequeue is ignored.

If more than one ENQ command is issued for a resource by a task, that resource remains owned by the task until the task issues a matching number of DEQ commands.


Quote:
But I had issued a DEQ command for the same resource before issuing ENQ then why it was queued. Please let me know your thoughts.

Have you done this at the end of trx or program processing or just before ENQ? if it just before the ENQ then then it shall ignore DEQ as happened with your case.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Nov 26, 2015 3:44 am
Reply with quote

I am using below for ENQ:
Code:
           EXEC CICS ENQ
               RESOURCE   (RESOURCE)
               LENGTH     (LENGTH OF RESOURCE)
               RESP       (RESPONSE-CD)
               NOHANDLE
            END-EXEC.     

And in the program it's DEQ and then ENQ and then 10 seconds Delay. So, for terminal 1, first DEQ is ignored as there is no ENQ and then Resource is ENQueued. Delay of 10 seconds is in place now.

Then (after 5 seconds) the transaction is started at terminal 2. So, a DEQ will be issued first and then ENQ and then 10 seconds delay to program end.

It takes a total of 20 seconds but as per me it should have taken less depending on when the transaction at terminal 2 was started (15 seconds in this case).

.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Thu Nov 26, 2015 4:33 am
Reply with quote

Quote:
Then (after 5 seconds) the transaction is started at terminal 2. So, a DEQ will be issued first and then ENQ and then 10 seconds delay to program end.

It wouldn't work that as per me as elaborated above. First ENQ then < Do all your processing> at the end issue DEQ. As I said that this works with same token and in your case when task 2 has started on term 2 it has violated the token (as token for task1 with tem1 was still in effect )and DEQ is ignore. That is what would have happened so if possible please try DEQ after ENQ.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Thu Nov 26, 2015 5:20 am
Reply with quote

Quote:
I am trying to see what happens if the resource is ENQueued by User1 and at the same time a DEQ is issued by User2


First ... Just remember that en/deq works because of an agreement on the enq token

an arbitrary string up to xxx(*) chars
(*) I do not remember how many icon_wink.gif

looks like You did not check the return code of the deq
dequeuing a resource which has not been enqueued should return an error

the same time might look like the same seen from the outside,
but if You look closer it might be pretty difficult to do it.

anyway, if done by the books, ENQ/DEQ WORKS.

tested in batch with two jobs

job 1
enq
wtor

deq

job 2
enq
wtor

deq

the ISPF enq report showed
job 1, holding the resource
job 2 waiting

as soon a reply was given for job 1
the two from job 2 appeared

CICS work the same way
transaction on term 1
enq
converse ( CONVERSATIONAL WRITE/READ )

deq

the same transaction on term 2
will display the screen as soon as enter is hit on terminal 1
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Nov 26, 2015 8:40 am
Reply with quote

Thanks for your comments Rohit and Enrico.

I have already read the following and I know that ENQ -> some processing -> DEQ works. But as mentioned below "A resource can be any string", I believe this string name is what you are referring to as a token. So, in my case, this "resource name" is same in DEQ and ENQ.

Quote:
A resource in the context of this command is any string of 1–255 bytes, established by in-house standards, to protect against conflicting actions between tasks, or to cause single threading within a program.

As you see below, there are 2 methods to enqueue a resource. I am using the second method where the argument represent the resource as I am providing the length in both DEQ and ENQ.
Quote:
The resource to be enqueued on must be identified by one of the following methods:

Specifying a data area that is the resource. It is the location (address) of the data area in storage that matters, not its contents.

Specifying a data area that contains a unique argument (for example, an employee name) that represents the resource. It is the contents of the data value that matters, not its location. LENGTH is required; the presence of the LENGTH option tells CICS to enqueue on the contents of the data value.

I hope you are getting what I am trying to say. My question is why DEQ is not ending the ENQ resource. According to what I have read, there's nothing stopping it.

*I know the purpose of ENQ/DEQ is to serialize and what I am stating will defeat the purpose But according to the theory I am not able to understand Why it doesn't work?
.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Thu Nov 26, 2015 12:27 pm
Reply with quote

Quote:
My question is why DEQ is not ending the ENQ resource.


because, as You say

Quote:
... the resource is ENQueued by User1 and at the same time a DEQ is issued by User2 ...


why do You expect that user2 would dequeue a resource enqueued by user1 ??? icon_eek.gif

the enq/deq mechanism checks that a resource is dequeued by the same process which enqueued it
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Thu Nov 26, 2015 1:39 pm
Reply with quote

enq
read update
rewrite
deq
is the normal suggested method should be used.
Resource name (string name) , I don't think that is just a token it would be resource name + task #= token.

You can not issue Deq first and enq later and if you do so the Deq is ignored as we have seen in your case. so if task 1 has issued enq and it is still active (which is your case) then no other task can Deq in between the processing of task1 except only task1 issues Deq or it ends or issues syncpoint only then the resources are unlocked or released.
And this has a performance issue too if you Deq first and enq later as then you are holding up resources even after updates unnecessarily.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1205
Location: Dublin, Ireland

PostPosted: Thu Nov 26, 2015 2:24 pm
Reply with quote

If it were possible for task2 to DEQ a resource that had been ENQ'ed by task1, that would make the ENQ/DEQ mechanism totally useless.

icon_rolleyes.gif icon_evil.gif

Garry
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Fri Nov 27, 2015 12:29 am
Reply with quote

Ok Guys. What you all are saying makes sense But
Where is it written that we can't do it?
Where is it written that DEQ will only affect ENQ from the same task/terminal/program?

That is all I want to see as I don't find it. The text only says Resource which is a string and can be used by anyone.

If you can provide a link then that would be really helpful.

.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Fri Nov 27, 2015 10:01 pm
Reply with quote

Quote:
Where is it written that we can't do it?
You can do it but it will be ignored and I mentioned that in my second post.
Quote:
Where is it written that DEQ will only affect ENQ from the same task/terminal/program?

Code:
When issuing the DEQ command, the resource to be dequeued from must be identified by the method used when enqueuing on the resource.
Same method here means the combination of (task+Resouce) , I think that is indeed.

I will try to find,if any links which say's this in black and white of what you say.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Fri Nov 27, 2015 10:08 pm
Reply with quote

Thanks Rohit But I have to disagree here.
Quote:
Same method here means the combination of (task+Resouce) , I think that is indeed.

Same method means one of these 2 methods (as mentioned above as well). So, if I am using Name + Length for ENQ then I have to mention Name + Length for DEQ as well and that is what I am doing.
Quote:
The resource to be enqueued on must be identified by one of the following methods:

Specifying a data area that is the resource. It is the location (address) of the data area in storage that matters, not its contents.

Specifying a data area that contains a unique argument (for example, an employee name) that represents the resource. It is the contents of the data value that matters, not its location. LENGTH is required; the presence of the LENGTH option tells CICS to enqueue on the contents of the data value.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Sat Nov 28, 2015 12:32 am
Reply with quote

Quote:
Thanks Rohit But I have to disagree here.

This should help to change your mind from Disagree to Agree mode(Specially last para).
Refer here

If you want to swim litter deeper the ocean then this way here


Quote:
So, if I am using Name + Length for ENQ then I have to mention Name + Length for DEQ as well and that is what I am doing.

Yes but should be done by the same TASK , this statement is in the SAME TASK context and not any other TASK.

Missing Bill O'Boyle 's Comments . He may have more specific explanation than what we have shared so far.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Sat Nov 28, 2015 1:43 am
Reply with quote

Rohit, Thanks for spending your time on this. I appreciate your efforts.

I disagreed on the statement that 'same method means task + resource'. Which I haven't seen written anywhere and which, I believe, is a completely different meaning of method. Method is how we are issuing the ENQ/DEQ commands. To me, TaskID is Not a part of method.

Moreover, the last para states
Quote:
After a task has issued an ENQ RESOURCE(data-area) command, any other task that issues an ENQ RESOURCE command with the same data-area parameter is suspended until the task issues a matching DEQ RESOURCE(data-area) command, or until the unit of work ends.

The text, which I think worth mentioning here, is
Quote:
matching DEQ RESOURCE(data-area) command

The question is: How are we matching the commands?

I believe, it is by mentioning Resource Name + Length in the ENQ/DEQ commands. And, what I believe you are saying is that, it is Resource Name + Length + TaskID. Most probably you are correct, I am only looking for a written proof of it.

.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Sat Nov 28, 2015 2:21 am
Reply with quote

Quote:
until the task issues a matching DEQ RESOURCE(data-area) command, or until the unit of work ends.

This is indeed in the same TASK context.

Because when Enq is issued in a task CWA is protected until it finds matching Deq issued in the same task(as quoted above though it is not written as you expect) or ends the task/transaction so during this process any other task (say task2) or a transaction issues
a.Enq then it will be suspended
b.Issues Deq it will be ignored(as there is no matching Enq by that
task2 is found prior).

It is all worth learning.. icon_smile.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Sat Nov 28, 2015 2:57 pm
Reply with quote

RahulG31, read this :

www-01.ibm.com/support/knowledgecenter/SSLTBW_1.13.0/com.ibm.zos.r13.hala001/f1a1d49023.htm%23wq61

And maybe you can do some research yourself?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2454
Location: Hampshire, UK

PostPosted: Sat Nov 28, 2015 7:26 pm
Reply with quote

Quote:
After a task has issued an ENQ RESOURCE(data-area) command, any other task that issues an ENQ RESOURCE command with the same data-area parameter is suspended until the task issues a matching DEQ RESOURCE(data-area) command, or until the unit of work ends.

TASK in the bold text in the above quote refers to the first task - not the second.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Sat Nov 28, 2015 10:19 pm
Reply with quote

Thanks Rohit. You've been real help.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Mon Nov 30, 2015 10:49 pm
Reply with quote

No Problem, Welcome!
This post on ENQ/DEQ would be a comprehensive ref. for others.
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 UNIX System Services Resource Busy All Other Mainframe Topics 7
No new posts Finding IMS resource blocker after se... IMS DB/DC 1
No new posts Limit CICS CPU resource CICS 0
No new posts How to find a CICS resource used in C... CICS 8
No new posts Issuing IMS-Commands from a program w... COBOL Programming 1
Search our Forums:

Back to Top