1

in my iPhone app, I have used 2 threads. Both functions differently in different class. On particular condition I want to pause particular thread so I have used
[NSThread sleepForTimeInterval:]
So my question is am I doing right or this sleep causes sleep in whole application? If yes what is other alternative?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mahesh
  • 662
  • 2
  • 11
  • 30

2 Answers2

2

If you want to pause your thread for a given amount of time, then [NSThread sleepForTimeInterval:] is just fine. However if you want to wait for a given event to occur (e.g. wait for another thread to catch up) you should take a look at the NSCondition class.

Alfonso
  • 8,386
  • 1
  • 43
  • 63
1

Yeah this is absolutely right. This will pause the current thread on which you are calling [NSThread sleepForTimeInterval:]

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184