Re: Stopwatch
Re: Stopwatch
- Subject: Re: Stopwatch
- From: Shawn Erickson <email@hidden>
- Date: Sun, 12 Jun 2005 12:30:30 -0700
On Jun 12, 2005, at 12:12 PM, Sanri Parov wrote:
On Sun, 12 Jun 2005 11:14:42 -0700, mmalcolm crawford wrote:
Use an NSTimer instead:
<http://developer.apple.com/documentation/Cocoa/Conceptual/Timers/
index.html>
Ok.
But that's not the point. When it comes to fire the timer, the whole
interface freezes.
Can you better explain the problem you are having? What are you doing
in that timer?
Best to say what you end goal is in more detail not just how you are
currently going about it.
That's why I used a different thread.
Which may be needed depending on what you are doing.
Now, I've managed to fire up a new thread... but I don't know how to
stop it when the user press
Implement your thread's loop like the following (running is a
boolean)...
while(running) {
....
}
...and set running to false when you want your thread to die (in
response to the user clicking your button). If you are going to play
around with threading I suggest you look up resource on programming
practices that deal with threads.
Some folks would say you have to define "running" as volatile but in
this case you don't need to since you don't need your thread to be in
lock step with anything else, you only want it to exit. Also the
optimizer will NOT optimize the reloading of running from memory
assuming you make any function / method calls in your loop (the
compiler has to assume that one of those function calls may have
change the value of running).
If you need more complex interlocking between your threads use
NSLock, NSConditionLock and friends or better yet if on Mac OS X 10.3
or latter use "@ synchronize(somePointer)" [1].
-Shawn
[1 <http://developer.apple.com/documentation/Cocoa/Conceptual/
ObjectiveC/LanguageOverview/chapter_3_section_9.html>
_______________________________________________
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