I'm porting an Android app I made to iOS. Android has a Yield() function to move the thread from running to the back(?) of the thread queue. This is useful so that this thread doesn't hog up too much CPU and make everything else sluggish. It works well in my Android app.
I'm using NSInvocationOperation objects to implement my threads. How do I add functionality similar to Android's (POSIX's) Yield()?
I'm using NSInvocationOperation objects to implement my threads.
This doesn't make a lot of sense. NSOperations are run in a thread, but they are not threads themselves, nor would they let you implement anything equivalent to a thread. If you really want a thread, use NSThread or pthread.
How do I add functionality similar to Android's (POSIX's) Yield()?
If you really want POSIX, try sched_yield(). At a higher level, there's pthread_yield_np() (np means non-portable -- there is no pthread_yield() in POSIX) -- but that does nothing but call sched_yield().
I wouldn't bother until you find that you actually need this, and that it helps. It's not at all common to do this sort of thing in iOS or Mac apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With