Timer and Touch Event concurrent issue

Nibbie
Posts: 4
Joined: 2009.08
Post: #1
Hi All,

I heard there is no multi-thread thing on iPhone, not sure how Touch Event and Timer work this out. I mean would Touch Event interrupt Timer thread?

For example:

Timer{ i++; }
TouchEnded{i--;}

So if timer never get interrupted by Touch Event, then i don't need to worry about anything, otherwise how to syncronize "i"?
Quote this message in a reply
Moderator
Posts: 1,552
Joined: 2003.10
Post: #2
claudie Wrote:I heard there is no multi-thread thing on iPhone

"multi-thread thing" could mean a number of different things, but the iPhone certainly lets you do preemptive multithreading.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.08
Post: #3
So is there any way to prevent NSTimer to get interrupted by touch event? I mean always let NSTimer to finish its work before processing touch event?
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
An NSTimer runs on a given thread, usually the main thread, unless specifically told otherwise. Events do, too. So, no, there is no preemption.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.08
Post: #5
Thanks guys. I did test myself, NSTimer and Event all handled by one thread(main thread), there is no multiple threading here. So there is no need to worry about concurrent. And after 7 hours debugging, i found out my bug is related to the way how i implement double link list, which made me thinking it was concurrent issue.

7 hours debugging!!! For you guys, it probably only need 7 mins, girls shouldn't do coding. Sign.
Quote this message in a reply
Moderator
Posts: 417
Joined: 2002.09
Post: #6
claudie Wrote:7 hours debugging!!! For you guys, it probably only need 7 mins, girls shouldn't do coding.

If you put in 7 hours of debugging on something, then either it was an assignment (ie. job or homework) or you REALLY want to code. Either way, you're going to code.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #7
If you want to use the normal setup(ie not do your own timing code) let the timer call your main loop. After your loop finishes it checks for touch events. It all can happen on one thread.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.08
Post: #8
Actually i was debugging for my boyfriend, he just throw this shit code to me ask me to find out what's wrong, and in the end it turns out he doesn't even know how to write a double linked list, how shit he is, i'm gonna dump him!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Timer Slows down in sleep mode chrism 13 5,205 Jun 14, 2009 05:36 PM
Last Post: longjumper
  iphone watchdog timer macnib 5 3,570 May 10, 2009 10:58 PM
Last Post: kodex
  UIScrollView pausing timer when scrolling duncster 1 2,556 Jan 14, 2009 01:00 PM
Last Post: duncster
  UIWebView touch event wonza 1 4,302 Dec 2, 2008 06:58 AM
Last Post: godexsoft