Re: Variable looses it's value
Re: Variable looses it's value
- Subject: Re: Variable looses it's value
- From: Nicko van Someren <email@hidden>
- Date: Thu, 16 Dec 2004 12:36:04 +0000
On 16 Dec 2004, at 12:07, Peter Karlsson wrote:
My variable is declared like this in my controller.h file:
int sysexcounter;
When I click on a button a new thread is started and I reset the
variable:
sysexcounter = 0;
...
And in the new thread I use this code to stop the flow until all bytes
have
been received.
If you are accessing the same variable from two different threads at
the same time you probably want to declare the variable "volatile",
e.g. "volatile int sysexcounter;", so that the compiler knows that the
value might change from look to the next. After all, as far as the
compiler is concerned, in the code segment:
while(sysexcounter < dumpSize)
{ usleep(1000000); // microseconds }
the variables sysexcounter aand dumpSize are loop invariant so the
conditional can be optimised outside the loop.
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden