• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Variable looses it's value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Variable looses it's value (From: "Peter Karlsson" <email@hidden>)

  • Prev by Date: Re: Variable looses it's value
  • Next by Date: Re: Getting Pixel values of an image
  • Previous by thread: Re: Variable looses it's value
  • Next by thread: RE: Variable looses it's value
  • Index(es):
    • Date
    • Thread