Author |
Message
|
ec10024 |
Posted: Thu Jun 30, 2016 3:44 am Post subject: atomic block and additional instances query |
|
|
Novice
Joined: 30 Jun 2016 Posts: 15
|
I am trying with a simple flow to increment the count which is a shared variable and total instances being 2.As it is not differentiating the instances and considering only one thread because of which I am getting updated count value.
DECLARE count SHARED INTEGER 0;
CREATE COMPUTE MODULE Input_No_MQMD_Compute
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
Val:BEGIN ATOMIC
SET count= count+1;
SET OutputRoot.XMLNSC.count =count;
END Val;
RETURN TRUE;
END;
Can anyone help me in understanding the ATOMIC and instances behavior? |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jun 30, 2016 4:01 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Atomic means that the operation only happens in one place at a time. If some other place tries to do the same operation at the same time, it waits until it's free.
But that doesn't mean that you enter the second atomic block (which has to wait) *after* the first atomic block completes.
So:
instance 1: Count = 0
instance 2: Count = 0
Instance 1: enter atomic with count = 0
Instance 2 : wait for atomic with count = 0
instance 1: exit atomic with count = 1
instance 2: enter atomic with count = 0 _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ec10024 |
Posted: Thu Jun 30, 2016 4:11 am Post subject: |
|
|
Novice
Joined: 30 Jun 2016 Posts: 15
|
but in my case I am getting
count = 1
count = 2
count = 3
count = 4
count = 5
which was not the expectation from me in case of multiple instances. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jun 30, 2016 4:14 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
What was your expectation?
It's a shared variable. There's only one copy of it in all instances of the flow in the same EG.
The 1,2,3,4,5 behavior is what I thought you wanted...
But there is still the scenario I mention where it's not set that way.
Although it is early and the coffee hasn't kicked in, so the scenario I outlined might not be possible. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ec10024 |
Posted: Thu Jun 30, 2016 4:17 am Post subject: |
|
|
Novice
Joined: 30 Jun 2016 Posts: 15
|
suppose If I run 4 messages at a time .how can I get count values to be 1,2,1,2 on declaring count as SHARED variable |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jun 30, 2016 4:26 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
ec10024 wrote: |
suppose If I run 4 messages at a time .how can I get count values to be 1,2,1,2 on declaring count as SHARED variable |
Do something other than add one to it each time. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Thu Jun 30, 2016 2:37 pm Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
ec10024 wrote: |
suppose If I run 4 messages at a time .how can I get count values to be 1,2,1,2 on declaring count as SHARED variable |
Add condition in ATOMIC block
if 2 then make that 1. |
|
Back to top |
|
 |
|