COMPGROUPS.NET | Post | Groups | Users | Stream | Browse | About | |

sync on local variable

• Permalink
• Email
• Follow

The IntelliJ code Inspector (lint) slapped my wrist for synchronising
on a local variable.  What's the problem with that?  The sync is on
the object, not the reference, right?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Don�t worry about people stealing an idea; if it�s original, you�ll have to shove it down their throats.
~ Howard Aiken (born: 1900-03-08 died: 1973-03-14 at age: 73)

 0
Reply Roedy 3/24/2010 10:11:15 PM

See related articles to this posting

Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable.  What's the problem with that?  The sync is on
> the object, not the reference, right?

Need SSCCE.

http://sscce.org/


 0
Reply markspace 3/24/2010 10:19:30 PM

Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable.  What's the problem with that?  The sync is on
> the object, not the reference, right?

Each thread gets its own local variable. Defeats the purpose of
synchronizing on one.

AHS

 0
Reply Arved 3/24/2010 10:46:40 PM

Arved Sandstrom wrote:
> Roedy Green wrote:
>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>> on a local variable.  What's the problem with that?  The sync is on
>> the object, not the reference, right?
>
> Each thread gets its own local variable. Defeats the purpose of
> synchronizing on one.

If you later export that local reference to another thread or object, it
should be fine.  It's valid to synchronize on a object that some other
part of the system will see later.

If you just synchronized on a local variable and then let it go out of
scope, yeah, that's a pretty serious "D'oh!" moment.


 0
Reply markspace 3/24/2010 10:55:30 PM

On 24-03-2010 18:11, Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable.  What's the problem with that?  The sync is on
> the object, not the reference, right?

Local variables are thread specific.

Passing on a local variable to another thread via some
global variable/singleton/cache would be a pretty bad design.

I can understand the complaint.

Arne

PS: yes - it is the object not the ref.

 0
Reply ISO 3/24/2010 11:09:17 PM

Arne Vajh�j wrote:
> On 24-03-2010 18:11, Roedy Green wrote:
>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>> on a local variable.  What's the problem with that?  The sync is on
>> the object, not the reference, right?
>
> Local variables are thread specific.
>
> Passing on a local variable to another thread via some
> global variable/singleton/cache would be a pretty bad design.
>
> I can understand the complaint.
>
> Arne
>
> PS: yes - it is the object not the ref.

It may be a case of import, rather than export. Suppose the method for
obtaining a reference to some object is fairly expensive, and
synchronized. Each thread could have obtained a reference to the same
object and cached it in a local variable.

It's difficult to know if the message was valid or not without an SSCCE.

Patricia

 0
Reply Patricia 3/24/2010 11:21:29 PM

On 24-03-2010 19:21, Patricia Shanahan wrote:
> Arne Vajh�j wrote:
>> On 24-03-2010 18:11, Roedy Green wrote:
>>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>>> on a local variable. What's the problem with that? The sync is on
>>> the object, not the reference, right?
>>
>> Local variables are thread specific.
>>
>> Passing on a local variable to another thread via some
>> global variable/singleton/cache would be a pretty bad design.
>>
>> I can understand the complaint.
>
> It may be a case of import, rather than export. Suppose the method for
> obtaining a reference to some object is fairly expensive, and
> synchronized. Each thread could have obtained a reference to the same
> object and cached it in a local variable.

It could be.

But I would tend to believe that would be messy as well. To be able to
easily verify that threads are indeed synchronizing on the same object,
then I think it is best if is relative simple to see what is being
synchronized on.

> It's difficult to know if the message was valid or not without an SSCCE.

I don't think the tool does super sophisticated code analysis. Most
likely it just have some simple rules and flag things that looks weird.
If they are good enough, then the developer can ignore the warning. And
a good tool would have the option to store the ignore decision.

Arne

 0
Reply ISO 3/24/2010 11:27:28 PM

Roedy Green wrote:
> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
> on a local variable.  What's the problem with that?  The sync is on
> the object, not the reference, right?

Right, it's not illegal and may be correct.  But it may be incorrect as
well, and probably is will be unless you can guarantee that the local will
point to the same instance in all threads.  IntelliJ thinks enough people
make that mistake that it's worth warning about. It's similar to

while (methodCall());
i++;

That's legal and  might be exactly what you meant to do, but the first
semicolon is likely enough to be spurious that a lint-like tool should say
something.


 0
Reply Mike 3/24/2010 11:36:39 PM

markspace wrote:
> Arved Sandstrom wrote:
>> Roedy Green wrote:
>>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>>> on a local variable.  What's the problem with that?  The sync is on
>>> the object, not the reference, right?
>>
>> Each thread gets its own local variable. Defeats the purpose of
>> synchronizing on one.
>
>
> If you later export that local reference to another thread or object, it
> should be fine.  It's valid to synchronize on a object that some other
> part of the system will see later.
>
> If you just synchronized on a local variable and then let it go out of
> scope, yeah, that's a pretty serious "D'oh!" moment.
>
I think all the responses have pretty much narrowed in on the same
things: the sync is indeed on the object, which means that however you
obtain/store a reference to that object that everything is using as a
lock, it's certainly legal to sync on an object referred to locally.

But since it's something that is somewhat unusual, and could (probably)
be a  mistake, I imagine IntelliJ is flagging it along the lines of what
Mike suggested.

AHS

 0
Reply Arved 3/25/2010 12:32:59 AM

On Wed, 24 Mar 2010 15:55:30 -0700, markspace <nospam@nowhere.com>
wrote, quoted or indirectly quoted someone who said :

>If you later export that local reference to another thread or object, it
>should be fine.  It's valid to synchronize on a object that some other
>part of the system will see later.

I have a JTable.  I get a row put it in a local variable and
synchronise on that.   Does that not lock anyone else getting that
row, even if they have nothing to do with my local variable?

AppToWatch row;
synchronized ( ALL_ROWS )
{
row = ALL_ROWS.get( rowIndex );
state = row.getState();
}
....
synchronized ( row )
{
url = row.getVersionURL();
marker = row.getMarker();
}
--
Roedy Green Canadian Mind Products
http://mindprod.com

Don�t worry about people stealing an idea; if it�s original, you�ll have to shove it down their throats.
~ Howard Aiken (born: 1900-03-08 died: 1973-03-14 at age: 73)

 0
Reply Roedy 3/25/2010 12:42:02 AM

On 24-03-2010 20:42, Roedy Green wrote:
> On Wed, 24 Mar 2010 15:55:30 -0700, markspace<nospam@nowhere.com>
> wrote, quoted or indirectly quoted someone who said :
>> If you later export that local reference to another thread or object, it
>> should be fine.  It's valid to synchronize on a object that some other
>> part of the system will see later.
>
> I have a JTable.  I get a row put it in a local variable and
> synchronise on that.   Does that not lock anyone else getting that
> row, even if they have nothing to do with my local variable?

It does.

But the code would probably be difficult to read and this
is why a code style checker flag it.

Arne

 0
Reply ISO 3/25/2010 1:25:16 AM

On 3/24/2010 8:42 PM, Roedy Green wrote:
> On Wed, 24 Mar 2010 15:55:30 -0700, markspace<nospam@nowhere.com>
> wrote, quoted or indirectly quoted someone who said :
>
>> If you later export that local reference to another thread or object, it
>> should be fine.  It's valid to synchronize on a object that some other
>> part of the system will see later.
>
> I have a JTable.  I get a row put it in a local variable and
> synchronise on that.   Does that not lock anyone else getting that
> row, even if they have nothing to do with my local variable?
>
>   AppToWatch row;
>   synchronized ( ALL_ROWS )
>                  {
>                  row = ALL_ROWS.get( rowIndex );
>                  state = row.getState();
>                  }
> ...
>    synchronized ( row )
>                      {
>                      url = row.getVersionURL();
>                      marker = row.getMarker();
>                      }

Are you sure you didn't misread IntelliJ's complaint?  The
thing that strikes me as odd about this code is that there are
three method calls made on row's object, only two of which are
synchronized on that object.  It's conceivable that this is all
right, but it sure looks strange to me -- and perhaps IntelliJ
thinks it peculiar, too.

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/25/2010 4:06:56 AM

On 3/24/2010 5:42 PM, Roedy Green wrote:
> On Wed, 24 Mar 2010 15:55:30 -0700, markspace<nospam@nowhere.com>
> wrote, quoted or indirectly quoted someone who said :
>
>> If you later export that local reference to another thread or object, it
>> should be fine.  It's valid to synchronize on a object that some other
>> part of the system will see later.
>
> I have a JTable.  I get a row put it in a local variable and
> synchronise on that.   Does that not lock anyone else getting that
> row, even if they have nothing to do with my local variable?
>
>   AppToWatch row;
>   synchronized ( ALL_ROWS )
>                  {
>                  row = ALL_ROWS.get( rowIndex );
>                  state = row.getState();
>                  }
> ....
>    synchronized ( row )
>                      {
>                      url = row.getVersionURL();
>                      marker = row.getMarker();
>                      }
I can't say for sure without seeing more of the code, but this looks
like a road to deadlock.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/25/2010 4:50:29 PM

On Thu, 25 Mar 2010 00:06:56 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
someone who said :

>     Are you sure you didn't misread IntelliJ's complaint?

all it says is  "synchronization on local variable row".
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 5:23:26 PM

On Thu, 25 Mar 2010 00:06:56 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
someone who said :

>>   AppToWatch row;
>>   synchronized ( ALL_ROWS )
>>                  {
>>                  row = ALL_ROWS.get( rowIndex );
>>                  state = row.getState();
>>                  }
>> ...
>>    synchronized ( row )
>>                      {
>>                      url = row.getVersionURL();
>>                      marker = row.getMarker();
>>                      }
>
>     Are you sure you didn't misread IntelliJ's complaint?  The
>thing that strikes me as odd about this code is that there are
>three method calls made on row's object, only two of which are
>synchronized on that object.  It's conceivable that this is all
>right, but it sure looks strange to me -- and perhaps IntelliJ
>thinks it peculiar, too.

I corrected the code to read:

AppToWatch row;
synchronized ( ALL_ROWS )
{
row = ALL_ROWS.get( rowIndex );
synchronized ( row )
{
state = row.getState();
}
}
...
synchronized ( row )
{
url = row.getVersionURL();
marker = row.getMarker();
}

Now I get TWO message about synchorizing on row.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 5:27:31 PM

On Wed, 24 Mar 2010 16:21:29 -0700, Patricia Shanahan <pats@acm.org>
wrote, quoted or indirectly quoted someone who said :

>It's difficult to know if the message was valid or not without an SSCCE.

you can see the complete code at
https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=/com/mindprod/vercheck/

it is a bit fat for a SSCCE.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 5:29:46 PM

On 3/25/2010 1:27 PM, Roedy Green wrote:
> [...]
> Now I get TWO message about synchorizing on row.

A politician would call this "Progress."  ;-)

Sorry; I'm out of ideas about what IntelliJ dislikes.  Let
us know if (no, let's be optimistic, "when") you find out; it'll
probably be interesting and/or instructive.

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/25/2010 5:38:21 PM

Roedy Green wrote:
> it is a bit fat for a SSCCE.

Well, the point of an SSCCE is that you trim down the "fat" code to a
minimal case that illustrates the problem.  Part of the value in doing
that is that you often find the problem in the course of doing the
trimming.

Eric Sosman
>> =A0 =A0 Are you sure you didn't misread IntelliJ's complaint? =A0The
>> thing that strikes me as odd about this code is that there are
>> three method calls made on row's object, only two of which are
>> synchronized on that object. =A0It's conceivable that this is all
>> right, but it sure looks strange to me -- and perhaps IntelliJ
>> thinks it peculiar, too.
>

Roedy Green wrote:
> I corrected the code to read:
>
> =A0 =A0AppToWatch row;
> =A0 =A0synchronized ( ALL_ROWS )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 row =3D ALL_ROWS.get( rowIndex );
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 synchronized ( row )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 state =3D row.getState();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0...

It's not clear to me how this next section gets its 'row' reference.
Presumably it has to synchronize on 'ALL_ROWS' via the above
fragment.  Regardless, any time you have inconsistent locking
protocols, e.g., using two locks in one place and only one in another,
you risk having strange problems, so it makes sense that IntelliJ
warns you about it.  As with "unchecked" warnings, that doesn't mean
that you're wrong, necessarily, only that you're in dangerous
territory.

> =A0 =A0 synchronized ( row )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 url =3D row.getVersionURL();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 marker =3D row.getMarker();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> Now I get TWO message about synchorizing on row.
>

It's very difficult to reason about locks and synchronization when
they depend on changeable references, and involve different locking
sequences.  I swan the warning is appropriate and you should either
live with it or come up with a locking protocol that's easier to
understand.

--
Lew

 0
Reply Lew 3/25/2010 6:01:30 PM

On 3/25/2010 1:29 PM, Roedy Green wrote:
> On Wed, 24 Mar 2010 16:21:29 -0700, Patricia Shanahan<pats@acm.org>
> wrote, quoted or indirectly quoted someone who said :
>
>> It's difficult to know if the message was valid or not without an SSCCE.
>
> you can see the complete code at
> https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=/com/mindprod/vercheck/
>
> it is a bit fat for a SSCCE.

Would have been nice of you to point out which of the twelve
source files elicited the complaint ...  For others who may want
a look, VerCheck.java seems to be the culprit.

Roedy, I still don't know what's going on, but there's at least
one synchronization problem apparent in the code:

for ( int rowIndex = 0; rowIndex < ALL_ROWS.size(); rowIndex++ )
...
synchronized ( ALL_ROWS )
{
row = ALL_ROWS.get( rowIndex );

As the comment just before this loop says, rows might be deleted
from ALL_ROWS while this is running, meaning that rowIndex might
be out of range by the time you call get().

This doesn't appear closely related to a complaint about
synchronizing on row -- but I've often found, when confronted
by a mysterious problem, that it pays to clean up *all* the
other issues, even those that are "obviously unrelated."

By the way, if ALL_ROWS can be perturbed while the loop is
in progress, the iteration may miss rows (visit row 4, other
thread deletes row 2 and slides everything down one slot, visit
row 5 which used to be row 6, never visit the old row 5), or may
visit a row more than once (visit row 4, other thread inserts a
row after row 2 and slides everything up, visit row 5 which is
the same row just visited as 4).  The comment indicates you don't
want to lock ALL_ROWS for the entire loop, but to keep the
iteration self-consistent you might want to do something like
lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
the iteration on the (private, stable) snapshot.

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/25/2010 6:06:53 PM

On Thu, 25 Mar 2010 11:01:30 -0700 (PDT), Lew <lew@lewscanon.com>
wrote, quoted or indirectly quoted someone who said :

>> it is a bit fat for a SSCCE.
>
>Well, the point of an SSCCE is that you trim down the "fat" code to a
>minimal case that illustrates the problem.  Part of the value in doing
>that is that you often find the problem in the course of doing the
>trimming.

The problem is any piece of code with a JTable in it and TableModel is
still going to be obese.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 6:35:38 PM

Roedy Green wrote :
> On Thu, 25 Mar 2010 00:06:56 -0400, Eric Sosman
> <esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
> someone who said :
>
> I corrected the code to read:

Have you tried to explicitly initialise row?

AppToWatch row = null;

>    synchronized ( ALL_ROWS )
>                   {
>                   row = ALL_ROWS.get( rowIndex );
>                   synchronized ( row )
>                       {
>                       state = row.getState();
>                       }
>                   }
>  ...
>     synchronized ( row )
>                       {
>                       url = row.getVersionURL();
>                       marker = row.getMarker();
>                       }
>
> Now I get TWO message about synchorizing on row.

--
Wojtek :-)


 0
Reply Wojtek 3/25/2010 6:48:26 PM

On 3/25/2010 11:35 AM, Roedy Green wrote:
> On Thu, 25 Mar 2010 11:01:30 -0700 (PDT), Lew<lew@lewscanon.com>
> wrote, quoted or indirectly quoted someone who said :
>
>>> it is a bit fat for a SSCCE.
>>
>> Well, the point of an SSCCE is that you trim down the "fat" code to a
>> minimal case that illustrates the problem.  Part of the value in doing
>> that is that you often find the problem in the course of doing the
>> trimming.
>
> The problem is any piece of code with a JTable in it and TableModel is
> still going to be obese.
Do you believe your problem is because of those classes? If not, you can
write an SSCCE that doesn't use them.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/25/2010 7:23:31 PM

On 3/25/2010 11:06 AM, Eric Sosman wrote:
> On 3/25/2010 1:29 PM, Roedy Green wrote:
>> On Wed, 24 Mar 2010 16:21:29 -0700, Patricia Shanahan<pats@acm.org>
>> wrote, quoted or indirectly quoted someone who said :
>>
>>> It's difficult to know if the message was valid or not without an SSCCE.
>>
>> you can see the complete code at
>> https://wush.net/websvn/mindprod/listing.php?repname=mindprod&path=/com/mindprod/vercheck/
>>
>>
>> it is a bit fat for a SSCCE.
>
> Would have been nice of you to point out which of the twelve
> source files elicited the complaint ... For others who may want
> a look, VerCheck.java seems to be the culprit.
>
> Roedy, I still don't know what's going on, but there's at least
> one synchronization problem apparent in the code:
>
> for ( int rowIndex = 0; rowIndex < ALL_ROWS.size(); rowIndex++ )
> ...
> synchronized ( ALL_ROWS )
> {
> row = ALL_ROWS.get( rowIndex );
>
> As the comment just before this loop says, rows might be deleted
> from ALL_ROWS while this is running, meaning that rowIndex might
> be out of range by the time you call get().
>
> This doesn't appear closely related to a complaint about
> synchronizing on row -- but I've often found, when confronted
> by a mysterious problem, that it pays to clean up *all* the
> other issues, even those that are "obviously unrelated."
>
> By the way, if ALL_ROWS can be perturbed while the loop is
> in progress, the iteration may miss rows (visit row 4, other
> thread deletes row 2 and slides everything down one slot, visit
> row 5 which used to be row 6, never visit the old row 5), or may
> visit a row more than once (visit row 4, other thread inserts a
> row after row 2 and slides everything up, visit row 5 which is
> the same row just visited as 4). The comment indicates you don't
> want to lock ALL_ROWS for the entire loop, but to keep the
> iteration self-consistent you might want to do something like
> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
> the iteration on the (private, stable) snapshot.
I agree except, don't use toArray, use new ArrayList<Row>();
Or, instead of all the sync, check, blah-de-blah, use the standard EDT
mechanisms for modifying/accessing this table.  That way, you're actions
are all serial, and you don't have to worry so much.

Threading isn't that hard to get right, but it isn't that hard to get
wrong either. The only truly difficult part of writing MT code is that
people aren't taught how to look at it and determine whether it is right
or not.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/25/2010 7:28:45 PM

On Thu, 25 Mar 2010 11:01:30 -0700 (PDT), Lew <lew@lewscanon.com>
wrote, quoted or indirectly quoted someone who said :

>It's very difficult to reason about locks and synchronization when
>they depend on changeable references,

They don't.  The two variables are final in the real code.  I
"simplified". My bad.

I think the problem is just that in general local variables can be
subject to casual modification, perhaps during a later patch, which
would break the lock.

--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 9:27:46 PM

On Wed, 24 Mar 2010 15:11:15 -0700, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>on a local variable.  What's the problem with that?  The sync is on
>the object, not the reference, right?

I got this response from an IntelliJ employee (probably a Russian with
ESL).

The point was synchronization only makes sense if two different
threads syncing on the same instance and question arises how safe was
an exchange, that two threads have same reference on their stacks.
Most obviously "clean" subject to synchronize on is a final field.
Synchronizing on a local reference might well be not a problem but
generally not that easy to verify for correctness and easy thing to
broke later.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 9:27:50 PM

On Thu, 25 Mar 2010 14:06:53 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
someone who said :

>     Would have been nice of you to point out which of the twelve
>source files elicited the complaint ...  For others who may want
>a look, VerCheck.java seems to be the culprit.

Sorry  I thought I had pointed you to Vercheck.java.

It has since occurred to me I could try concocting a much simpler
piece of code without any JTable that still triggered the lint.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 9:29:33 PM

On Thu, 25 Mar 2010 12:28:45 -0700, Daniel Pitts
<newsgroup.spamfilter@virtualinfinity.net> wrote, quoted or indirectly
quoted someone who said :

>Threading isn't that hard to get right, but it isn't that hard to get
>wrong either. The only truly difficult part of writing MT code is that
>people aren't taught how to look at it and determine whether it is right
>or not.

The compiler rarely complains and the program nearly always run one
thread at a time. You can't easily simulate pathological cases the way
you can with single thread.  Perhaps there is some drug that induces
paranoia that could be used once you have your first cut.
--
Roedy Green Canadian Mind Products
http://mindprod.com

If you tell a computer the same fact in more than one place, unless you have an automated mechanism to ensure           they stay in sync, the versions of the fact will eventually get out of sync.

 0
Reply Roedy 3/25/2010 9:32:39 PM

Roedy Green wrote:

> I got this response from an IntelliJ employee (probably a Russian with
> ESL).

Hmm, well that's one strike against IntelliJ then, if they don't hire
tech support that can communicate properly.

 0
Reply markspace 3/25/2010 10:12:36 PM

On 25-03-2010 17:27, Roedy Green wrote:
> On Wed, 24 Mar 2010 15:11:15 -0700, Roedy Green
> <see_website@mindprod.com.invalid>  wrote, quoted or indirectly quoted
> someone who said :
>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>> on a local variable.  What's the problem with that?  The sync is on
>> the object, not the reference, right?
>
> I got this response from an IntelliJ employee (probably a Russian with
> ESL).
>
> The point was synchronization only makes sense if two different
> threads syncing on the same instance and question arises how safe was
> an exchange, that two threads have same reference on their stacks.
> Most obviously "clean" subject to synchronize on is a final field.
> Synchronizing on a local reference might well be not a problem but
> generally not that easy to verify for correctness and easy thing to
> broke later.

JetBrains is a czech company, so czech not russian sounds more
likely.

But the text looks fine to me. It is more or less what we
have been telling you for two days.

Arne


 0
Reply ISO 3/25/2010 11:41:39 PM

On 25-03-2010 15:28, Daniel Pitts wrote:
> Threading isn't that hard to get right, but it isn't that hard to get
> wrong either. The only truly difficult part of writing MT code is that
> people aren't taught how to look at it and determine whether it is right
> or not.

That applies to other things than MT!

:-)

Arne


 0
Reply ISO 3/25/2010 11:59:28 PM

On Wed, 24 Mar 2010, Roedy Green wrote:

> The IntelliJ code Inspector (lint) slapped my wrist for synchronising on
> a local variable.  What's the problem with that?  The sync is on the
> object, not the reference, right?

It's like the warning on the lack of a serialVersionUID in a Serializable
class. It isn't necessarily wrong, but there is a popular class of errors
that involve doing this.

tom

--
life finds a way

 0
Reply Tom 3/26/2010 3:01:49 AM

On 3/25/2010 3:28 PM, Daniel Pitts wrote:
> On 3/25/2010 11:06 AM, Eric Sosman wrote:
>> [... about iterating over a changing List ...]
>> to keep the
>> iteration self-consistent you might want to do something like
>> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
>> the iteration on the (private, stable) snapshot.
>
> I agree except, don't use toArray, use new ArrayList<Row>();

Not confrontational, just curious: Why prefer a new ArrayList
to an array?  To me, it appears that an ArrayList is just an array
wrapped up in extra machinery, and I can't see that the machinery
adds any value for this usage.  So, why pay the extra freight?
What am I missing?

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/26/2010 2:22:01 PM

On 3/26/2010 7:22 AM, Eric Sosman wrote:
> On 3/25/2010 3:28 PM, Daniel Pitts wrote:
>> On 3/25/2010 11:06 AM, Eric Sosman wrote:
>  >> [... about iterating over a changing List ...]
>>> to keep the
>>> iteration self-consistent you might want to do something like
>>> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
>>> the iteration on the (private, stable) snapshot.
>  >
>> I agree except, don't use toArray, use new ArrayList<Row>();
>
> Not confrontational, just curious: Why prefer a new ArrayList
> to an array? To me, it appears that an ArrayList is just an array
> wrapped up in extra machinery, and I can't see that the machinery
> adds any value for this usage. So, why pay the extra freight?
> What am I missing?
Array is a relatively primitive concept. You're question is akin to
asking why use a "Date object" instead of an "int representing the
milliseconds since Jan 1, 1970".

Either one "works". Yes, the non-primitive has more "machinery", but
that isn't automatically a bad thing.  The primitive looses semantic
meaning outside of its context, where a properly designed abstraction
maintains its semantics regardless of context.

Lists are also easier to work with, and work in more places.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/26/2010 8:15:47 PM

On 3/25/2010 2:27 PM, Roedy Green wrote:
> On Wed, 24 Mar 2010 15:11:15 -0700, Roedy Green
> <see_website@mindprod.com.invalid>  wrote, quoted or indirectly quoted
> someone who said :
>
>> The IntelliJ code Inspector (lint) slapped my wrist for synchronising
>> on a local variable.  What's the problem with that?  The sync is on
>> the object, not the reference, right?
>
> I got this response from an IntelliJ employee (probably a Russian with
> ESL).
>
> The point was synchronization only makes sense if two different
> threads syncing on the same instance and question arises how safe was
> an exchange, that two threads have same reference on their stacks.
> Most obviously "clean" subject to synchronize on is a final field.
> Synchronizing on a local reference might well be not a problem but
> generally not that easy to verify for correctness and easy thing to
> broke later.
One thing you can do is more the synchronization into the "Row" class,
and turn your operations into atomic operations, rather than have
external clients need to concern themselves with synchronization.

That way, the Row class can always sync on the same object (probably
"this", but not necessarily), and the client needn't care about it.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/26/2010 8:18:07 PM

Daniel Pitts wrote:
> On 3/26/2010 7:22 AM, Eric Sosman wrote:
>> On 3/25/2010 3:28 PM, Daniel Pitts wrote:
>>> On 3/25/2010 11:06 AM, Eric Sosman wrote:
>>  >> [... about iterating over a changing List ...]
>>>> to keep the
>>>> iteration self-consistent you might want to do something like
>>>> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
>>>> the iteration on the (private, stable) snapshot.
>>  >
>>> I agree except, don't use toArray, use new ArrayList<Row>();
>>
>> Not confrontational, just curious: Why prefer a new ArrayList
>> to an array? To me, it appears that an ArrayList is just an array
>> wrapped up in extra machinery, and I can't see that the machinery
>> adds any value for this usage. So, why pay the extra freight?
>> What am I missing?
> Array is a relatively primitive concept. You're question is akin to
> asking why use a "Date object" instead of an "int representing the
> milliseconds since Jan 1, 1970".
>
> Either one "works". Yes, the non-primitive has more "machinery", but
> that isn't automatically a bad thing.  The primitive looses semantic
> meaning outside of its context, where a properly designed abstraction
> maintains its semantics regardless of context.
>
> Lists are also easier to work with, and work in more places.
>
I tend to use an array where the underlying structure I am representing
really is an array, and a collection where the underlying structure
really is a list or set or whatever.

Specifically I am not going to use an ArrayList, for example, if the
thing being modelled is not resizable. Why would I want to write code to
ensure that the ArrayList will stay at a fixed size when an aray will
already take care of that for me?

AHS

 0
Reply Arved 3/26/2010 9:05:27 PM

On 3/26/2010 4:15 PM, Daniel Pitts wrote:
> On 3/26/2010 7:22 AM, Eric Sosman wrote:
>> On 3/25/2010 3:28 PM, Daniel Pitts wrote:
>>> On 3/25/2010 11:06 AM, Eric Sosman wrote:
>> >> [... about iterating over a changing List ...]
>>>> to keep the
>>>> iteration self-consistent you might want to do something like
>>>> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
>>>> the iteration on the (private, stable) snapshot.
>> >
>>> I agree except, don't use toArray, use new ArrayList<Row>();
>>
>> Not confrontational, just curious: Why prefer a new ArrayList
>> to an array? To me, it appears that an ArrayList is just an array
>> wrapped up in extra machinery, and I can't see that the machinery
>> adds any value for this usage. So, why pay the extra freight?
>> What am I missing?
> Array is a relatively primitive concept. You're question is akin to
> asking why use a "Date object" instead of an "int representing the
> milliseconds since Jan 1, 1970".

I think you've over-generalized my question.  I'm not
asking whether arrays or Lists (longs or Dates) are preferable
in all circumstances, nor even in most circumstances.  Rather,
I'm asking why you prefer the "heavier" object in the particular
situation Roedy faces.

> Either one "works". Yes, the non-primitive has more "machinery", but
> that isn't automatically a bad thing.

Okay.  I'd also say it's not automatically a good thing,
especially when the machinery is not going to be used.

How much extra machinery are we talking about, in this specific
case?  I'm suggesting a call to toArray() followed by an iteration
over the array: One new object created.  A new ArrayList involves
creating that same array (perhaps twice, but I don't know whether
that happens here; there's a bug number I haven't looked up), creates
the ArrayList itself, and creates an Iterator when you actually do
the traversal.  Three (four?) new objects instead of one.

How heavy are the extra objects?  The ArrayList carries two
fields, plus another inherited from AbstractList.  The Iterator
carries four more fields (you'll only see three in the source,
but inner classes carry a hidden reference to their owner).
During the iteration, the Iterator carefully checks whether the
ArrayList has been modified; we know it will not have been (the
reason we made the snapshot was so no modifications would disturb
us).  Each item retrieved takes three bounds checks (nominally)
instead of one: One in hasNext(), one in next(), and one in the
actual array fetch.  And so on.

Okay, okay, okay: Memory's cheap, CPU's are fast, only misers
count their change.  But on the other hand, "Take care of the
pennies and the pounds will take care of themselves," and "Don't
use a cannon to kill a canary."

> The primitive looses semantic
> meaning outside of its context, where a properly designed abstraction
> maintains its semantics regardless of context.

The comparison is between an array and an ArrayList.  The
only semantic difference I see between them is that the latter
can grow and shrink, while the former cannot.  But in the case
at hand, the goal is to get a snapshot that will remain unchanged,
that is, to avoid growth and shrinkage.  Again, it seems to me
we're paying for capabilities that will not be used.

> Lists are also easier to work with, and work in more places.

Once again, I return to the particular use in consideration.
The comparison is between

Row[] rows;
synchronized(ALL_ROWS) {
rows = ALL_ROWS.toArray(new Row[ALL_ROWS.size()]);
}
for (Row r : rows) { ... }

and

ArrayList<Row> rows;
synchronized(ALL_ROWS) {
rows = new ArrayList<Row>(ALL_ROWS);
}
for (Row r : rows) { ... }

There's only one "place" to consider, but still: Point to you
for being easier by five keystrokes.  (With a simple change I
could get a fourteen-key swing and beat you by nine, but at the
cost of creating two arrays instead of one.)

Even though my first language was FORTRAN, I have no special
love for the array nor no special antipathy for the List.  I'm
happy to use either.  But I *do* have a preference for lighter-
weight gadgets when they're adequate for the purpose at hand, and
a Yankee's aversion to paying for unused extras.  YM[*]MV.

[*] Motivation.

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/26/2010 9:33:16 PM

On 3/26/2010 4:18 PM, Daniel Pitts wrote:
> [...]
> One thing you can do is more the synchronization into the "Row" class,
> and turn your operations into atomic operations, rather than have
> external clients need to concern themselves with synchronization.
>
> That way, the Row class can always sync on the same object (probably
> "this", but not necessarily), and the client needn't care about it.

Are you sure he can do that?  He calls three methods on
the row instance, in two synchronized blocks.  Split them into
three blocks, and the pair that were together may no longer see
their row in the same state, because something may happen after
one method releases the lock and before the next acquires it.

--
Eric Sosman
esosman@ieee-dot-org.invalid

 0
Reply Eric 3/26/2010 10:19:03 PM

On 26-03-2010 10:22, Eric Sosman wrote:
> On 3/25/2010 3:28 PM, Daniel Pitts wrote:
>> On 3/25/2010 11:06 AM, Eric Sosman wrote:
>  >> [... about iterating over a changing List ...]
>>> to keep the
>>> iteration self-consistent you might want to do something like
>>> lock ALL_ROWS, grab a snapshot with toArray(), unlock, and run
>>> the iteration on the (private, stable) snapshot.
>  >
>> I agree except, don't use toArray, use new ArrayList<Row>();
>
> Not confrontational, just curious: Why prefer a new ArrayList
> to an array? To me, it appears that an ArrayList is just an array
> wrapped up in extra machinery, and I can't see that the machinery
> adds any value for this usage. So, why pay the extra freight?
> What am I missing?

As a general rule:

know that more functionality than array will be needed in the future =>
pick ArrayList

know that more functionality than array will NOT be needed in the future
=> pick array

don't know if more functionality than array will be needed in the future
=> pick ArrayList

My assumption would be that in the real world that would be 10%-10%-80%.

Obviously you can argue that this seems fell in category #2.

Arne


 0
Reply ISO 3/27/2010 12:59:50 AM

On 3/26/2010 3:19 PM, Eric Sosman wrote:
> On 3/26/2010 4:18 PM, Daniel Pitts wrote:
>> [...]
>> One thing you can do is more the synchronization into the "Row" class,
>> and turn your operations into atomic operations, rather than have
>> external clients need to concern themselves with synchronization.
>>
>> That way, the Row class can always sync on the same object (probably
>> "this", but not necessarily), and the client needn't care about it.
>
> Are you sure he can do that? He calls three methods on
> the row instance, in two synchronized blocks. Split them into
> three blocks, and the pair that were together may no longer see
> their row in the same state, because something may happen after
> one method releases the lock and before the next acquires it.

The first call is synchronized separately.  The second and third call
are in one synchronized block.  The "atomicity" of those two calls can
be handled in one method:

class MarkedUrl {
private final VersionURL url;
private final Marker marker;

// appropriate contstructor and getters.
}

public class AppToWatch  {
public syncronized MarkedUrl getMarkedUrl() {
return new MarkedUrl(versionUrl, marker);
}
}

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0
Reply Daniel 3/29/2010 7:52:35 PM
 comp.lang.java.programmer 51828 articles. 38 followers.

38 Replies
246 Views

Similar Articles

[PageSpeed] 35

• Permalink
• Email
• Follow

 Reply:

Similar Artilces:

(local-variables/warning) Error in File local-variables
Hi below is the error message that I get when opening some verilog and systemC files with Xemacs on a Fedora 8 x86 machine I have no clue what all these errors mean. I guest it is related to my .init.el file. I just took a file that I used many years ago. I have include the complete file below too. Thanks for any hint. nike (1) (local-variables/warning) Error in File local-variables: Symbol's value as variable is void: compile-command Backtrace follows: verilog-modify-compile-command() run-hooks(verilog-modify-compile-command) # bind (force) hack-local-variables(...

(local-variables/warning) File local-variables error: Symbol's value as variable is void: compile-command
Hi I get the following error message when I start my xemacs in a directory containing a desktop file (see below). (local-variables/warning) File local-variables error: Symbol's value as variable is void: compile-command I have tried starting xemacs with -init_debug but I did not get any further info. Thanks for any hint. GA ;;;;;;;;;;;;;;;;;;;;;;;;; desktop file begins here ;; -------------------------------------------------------------------------- ;; Desktop File for Emacs ;; -------------------------------------------------------------------------- ;; Created Wed A...

File local variables and function hack-one-local-variable in files.el
I put the following at the bottom of a file of source code (True Basic, http://www.truebasic.com/) ! Local Variables: ! mode: outline ! outline-regexp:"^! @+" ! End: and got an error message about lack of the prefix "! " for the line ! outline-regexp:"^! @+" Investigating, I found that the function hack-one-local-variable in files.el was jumping to the beginning of the buffer for that file when setting the mode. My version is XEmacs 21.4 (patch 8) "Honest Recruiter (Windows [3])" [Lucid] (i586-pc-win32) of Sun Jun 16 2002 on T...

local variables and global variables
Hi, How and what should be used to define a local variable and a global variable as well. and if i have used a sub-routine in a script and i want to use that sub-routine in another script, how can i do that. regards king wrote: > How and what should be used to define a local variable and a global > variable as well. In Perl variables are defined by assigments. You simply do $var = <expr>; > and if i have used a sub-routine in a script and i want to use that > sub-routine in another script, > how can i do that. You define the subroutine in a module and then impor... reference variable and local variable I was curious and playing with pointers and references to see what's different between them. Other than the obvious ones involving C++ syntax & things like references cannot be modified with addition & subtraction, pointers can be modified, both are similar. It stated me going what are the diferrence between a reference vairable and local variable ? Here are what I can think of 1. For a local variable constructor is called, not the case for a reference variable. 2. Local variable cannot be NULL. Reference variable can point to a NULL object by a simple trick like. Employee* e = NUL... How to Get Local Variables That Are Not So Local Dear SQLers: I have written a longish script. I am up to just over 800 lines, and there is way more to come yet. In it, I define a number of stored procedures. I have test code for most of them. My script looks something like: setup database create tables and indexes repeat n times create procedure test procedure check table results end off I would like the option of easily turning off the testing. 1) I wish I could define a variable at the start of the script and check that with eac... Setting a .local variable named by a variable Is there a way of setting a .local variable, using a variable as the name (or part of it) other than using Interpret as follows: interpret '.local~'db'.connection="B1"' So, if the variable "db" contained "stuff" then: Say .stuff.connection /* B1 */ -- Steve Swift http://www.swiftys.org.uk/swifty.html http://www.ringers.org.uk On Mar 10, 10:42=A0am, Swifty <steve.j.sw...@gmail.com> wrote: > Is there a way of setting a .local variable, using a variable as the > name (or part of it) other than using Interpret as follows: > > ... Block variable & Local variable Hi What does happen for "num" variable in this code : array = [1,2,3,4,5] x = 1 num = 1 array.each { |num| puts num*20 + x } ( after this code when I type "puts num , ruby return 5 ! why? ) -- Posted via http://www.ruby-forum.com/. |num| inside block iterates through array's items. Last item in array is 5, thus |num| value will be the one from last iteration of 'each' method. It is better to rename |num| to something else, |item| for example. ----- Eugen On 08/03/2010 11:19 AM, Amir Ebrahimifard wrote: > Hi > What does happen for &q... Instance Variable vs Local Variable Hi When delegating a compareTo method for a playing card to a Comparator, I wasn't sure whether to go for the instance variable or local variable approach: public class Card implements Comparable { static class SortByValueThenSuit implements Comparator { public int compare(Object o1, Object o2) { ... } } // local variable approach public int compareTo(Object o) { return new SortByValueThenSuit().compare(this, o); } // instance variable approach private SortByValueThenSuit sorter = new SortByValueT... Instance Variable v.s. Local Variable What is the difference between instance variable and local variable? Is that true instance variables are shared among threads while local variable is not shared? public class Test { private String var1; // is this instance variable? public int var2; // is this also instance variable? private void method1() { String var3; // is this local variable? } } Thanks a lot! Yes your comments are correct, Instance variables are class level member variables. Local variables are defined in a method/block. Local variables are not shared amongst thread. Jerry wrote: &... Export local variable to global variable scope? Hello, I have a function, e.g. function foo() { include("bar.php"); } and the bar.php contain contents e.g.$global_v1 = "abc"; $global_v2 = "def"; I want to execute function foo(), but at the same time, let the variables declared in bar.php to have global scopem is it possible? Thanks. howa wrote: > Hello, > > I have a function, e.g. > > function foo() { > include("bar.php"); > } > > and the bar.php contain contents e.g. > >$global_v1 = "abc"; > $global_v2 = "def"; > > I w... Are local variables accessible from local object methods? Hi, C55ee on WIndows 2000 pro I have a local variable xRecordsRead LONG which I'm incrementing in one of my local classes methods. If I set a message inside the class I can see it is being incremented, but if I set a messaged outside of the class method (in the main procedure) it shows a value of 0... I thought local variables where available inside local methods.... Am I wrong? Best regards Edgard L. Riba You need to use the debugger to be absolutely sure of this. Message is too dangerous and you cannot rely on what it is telling you. If you have a locally declared var... Accessing a global variable when there is a local variable in the same name int i = 10; int main() { int i = 20; return 0; } Hi All, I want to access the global variable i inside the main. Is there a way to do this in C? Regards, Mohan. Mohanasundaram wrote: > int i = 10; > int main() > { > int i = 20; > return 0; > } > > Hi All, > > I want to access the global variable i inside the main. Is there > a way to do this in C? By not masking it with a redeclaration inside main. On 2004-06-25, Mohanasundaram <mohanasundaram@msn.com> wrote: > int i = 10; > int main() > { > int i = 20; > retu... dynamic initialization of local an non-local static variables A contrived example and questions below: #include <iostream> struct A { A(const char* msg) { std::cout << msg << std::endl; } }; A non_local("non-local"); A& singleton() { static A local("local"); return local; } int main() { std::cout << "main" << std::endl; singleton(); } 1) What are the possibilities here? Can "non-local", "local", and "main" be printed in any order by conforming compiler? Do I understand correctly that the standard allows dynamic ... Member variable versus local variable access performance Lets say you have a method that is called hundreds of times a second and its job is to write data to a variety of variables (ints, doubles, strings, etc.). These values aren't needed after the method completes. Would it be more efficient to keep member variables as part of the class in which to insert the data? Or just declare local variables inside the method each time its called? See the 2 examples below. class thisClass { public: void callback() { int varA; double varB; std::string varC; varA = retrieveIntFromAnotherS... different handling of local variables and instance variables when undefined Hello, I somehow stumbled over a, how I think, strange behavior. When I try to handle a undefined variable in irb I get something like that: irb(main):001:0> !blubb NameError: undefined local variable or method `blubb' for main:Object from (irb):1 But when I do the same with a undefined instance variable I get: irb(main):002:0> !@blubb => true I think that is somehow strange. Because of that I have overseen a mispelling in the instance variable name. Is that the wanted behavior? Regards, Tammo On Sep 12, 3:59 pm, Tammo Tjarks <ta...@tammo-tjarks.de> wrote: &g... What? Assigning a session variable also assigns the local variable? Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code:$frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is$frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc. thecrow wrote: > Alright, what the hell is going on here? > > In the following code, I expect the printed ...

Can we make a local variable in a function as global variable???
I have some local variables defined in one method and Can I make those variables as global variables? If so , can any one explain me how can I do that Thanks, Sairam On Apr 5, 3:19 am, "sairam" <sai...@gmail.com> wrote: > I have some local variables defined in one method and Can I make those > variables as global variables? If so , can any one explain me how can > I do that > > Thanks, > Sairam ----------- num = None def f1(): global num num = 30 def f2(): print num f1() f2() ----------- You can read from a global variable, but to assign to...

local variables
Good day! I'd like to construct some strings (actually, names of TIKZ nodes / coordinates, but my problem is independent of TIKZ). As they should be constructed in a consistent way, I'd like to use a macro (\getposname) for this task. In this macro, I'd like to use something like local variables. Unfortunately, it is not obvious to me, how to achieve this. The following minimized example shows the problem: ---------------------------- \documentclass{article} \begin{document} \def\getposname{% \def\dummy{foo}% comment this line to get \coordinate to work ...

Atmel Studio 6: local variable not shown at Locals Window
I am testing the sample project ADS7843_EXAMPLE1 with SAM3S-EK2 and Atmel Studio 6. I am using SAM-ICE (SEGGER) for debug via JTAG. I set a break point at main function and debug the project, and it did stop at the break point. The first line of code at main function is a definition of a local variable. uint8_t uc_result = 0; However, I didn't see this local variable being shown at "Locals" window. I tried to add this variable to "Watch 1" window, and got the following error: Name Value Type uc_result ...

local variables
> He doesn't like local variables much, either. Taken from another thread. I remember covering this before many years ago, but it's like I'm learning this language all over again. Too much time away from it (although not actually having seriously programmed in it might be the problem). Can you refresh my memory why Chuck doesn't like local variables? I don't like local variables. I'm still trying to wrap my brain around why it's considered "safe". -- Richard S. Westmoreland http://www.antisource.com "Richard S. Westmoreland" <ric...

local variable is changed when changing global variable inside procedure
A procedure call CALL OVERF�R_PKU_PKI(DCLV012223.VNR_ISO,' ', DCLV012223.AKS_BEV_AKSJEBEH); to the following procedure OVERF�R_PKU_PKI: PROC(VNR,TYPE,SUM); DCL VNR CHAR(12); PUT SKIP LIST('VNR '!!VNR); DCL TYPE CHAR(3); DCL SUM FIXED DEC(15); TELLER = TELLER + 1; DCLV012223 = ''; .. .. .. PUT SKIP LIST('VNR1 '!!VNR); gives a result that indicates that the DCLV012223 = ''; statement has also blanked the VNR variable How can this be possible? I would have expected that a change of a global variable inside i procedure should n...

Local Variables in Do[]
I hate to have such a newbie question, but I'm new to programming in Mathematica. I have nested loops, and I'd like to change a global variable inside of the loop. It seems that Mathematica makes all variables defined inside of Do functions local, is this true? ...

Local variables
Hi all Suppose I have a very big matrix A. Now, I want to send it to a function f, i.e. f(A). For example f could be: function y=f(x) y=x(1,1); When calling functions the in-parameters are copied to local variables, right? If so more memory is allocated. If A in this example covers more then half the availble memory I will get 'out of memory'-error when calling f. Is there a way not to copy the entire matrix but to send a pointer instead? Thanks in advance Fred Fred wrote: > > > Hi all > > Suppose I have a very big matrix A. Now, I want to send it to a > function...