Author |
Message
|
jfluitsm |
Posted: Wed Jan 17, 2007 2:36 am Post subject: shared constant and atomic access |
|
|
Disciple
Joined: 24 Feb 2002 Posts: 160 Location: The Netherlands
|
Is the access to SHARED CONSTANTs also implicit atomic as with SHARED variables, or does the softwae know that atomic access to a constant is not needed? _________________ Jan Fluitsma
IBM Certified Solution Designer WebSphere MQ V6
IBM Certified Solution Developer WebSphere Message Broker V6 |
|
Back to top |
|
 |
mgk |
Posted: Wed Jan 17, 2007 4:16 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Why would you want to make a constant SHARED? That would be a bad idea in my opinion as it is just not needed. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
jfluitsm |
Posted: Wed Jan 17, 2007 4:26 am Post subject: |
|
|
Disciple
Joined: 24 Feb 2002 Posts: 160 Location: The Netherlands
|
I have a large group of constants. To make them shared reduces the memory usage with miltiple instances.
When the access to shared constants is atomic the memory gain is outweighted by the extra processing and serialization of the atomic code. _________________ Jan Fluitsma
IBM Certified Solution Designer WebSphere MQ V6
IBM Certified Solution Developer WebSphere Message Broker V6 |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 4:40 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Unless you have specific profiling information that shows that SHARED CONSTANTs use less memory than regular constants, I'd take mgk's word that it's not necessary.
Also, I didn't think access to SHARED variables was implicitly atomic?
Looking at http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/topic/com.ibm.etools.mft.doc/ak04940_.htm a little closer... it kind of depends on what you mean I guess. It says "It is also unnecessary to use the BEGIN ATOMIC construct on reads and writes to shared variables", which supports your statement... But then it clearly shows an example using a counter where the BEGIN ATOMIC is necessary in order to ensure that two updates don't overwrite each other. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jfluitsm |
Posted: Wed Jan 17, 2007 6:27 am Post subject: |
|
|
Disciple
Joined: 24 Feb 2002 Posts: 160 Location: The Netherlands
|
Thanks Jeff,
As far as I understood the shared variables are only instantiated once for all threads (multiple inputnodes and/or multiple instances), hence the reduced memory usage.
I guess you are refering to the sample 'SET count = count + 1'.
What happens with the sample is that 'count' is accessed twice, once to get the old value and once to set the new value. Both actions are implicit atomic, but in between (during the calculation) 'count' can be changed by another thread. _________________ Jan Fluitsma
IBM Certified Solution Designer WebSphere MQ V6
IBM Certified Solution Developer WebSphere Message Broker V6 |
|
Back to top |
|
 |
|