Igor Delovski Board Forum Index Igor Delovski Board
My Own Personal Slashdot!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NSOperation & Multithreading

 
Post new topic   Reply to topic    Igor Delovski Board Forum Index -> Mac Cocoa
Mac Cocoa  
Author Message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3136
Location: Europe

PostPosted: Fri Nov 20, 2009 6:04 pm    Post subject: NSOperation & Multithreading Reply with quote

Marcus Zarra - Cocoa Tutorial: NSOperation and NSOperationQueue

"Fortunately, Apple has made a lot of progress in OS X 10.5 Leopard. NSThr-
ead itself has received a number of very useful new methods that make thr-
eading easier. In addition, they have introduced two new objects: NSOpera-
tion and NSOperationQueue. In this Tutorial I will walk through a basic exam-
ple that shows how to use these new Objects and how they make multi-thr-
eading your application nearly trivial."
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3136
Location: Europe

PostPosted: Fri Nov 20, 2009 6:06 pm    Post subject: Reply with quote

SO - iPhone - return from an NSOperation

"I am using a subclass of NSOperation to do some background processes.
I want the operation to be cancelled when the user clicks a button. To can-
cel an operation (on a button click for instance), I tried calling -cancel but it
doesn't make a difference. Also tried calling -finish but even that doesn't
change anything."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Sat Jan 02, 2010 1:34 am    Post subject: Reply with quote

iPhone - Posix Threads for the win

"I found that using Posix threads were slightly (1-2%) faster than NSThre-
ads. Currently, I've set my engine up to have 2 additional threads. One to
handle the game updating and rendering, and a second to handling job lo-
ading, with jobs being streaming in audio and textures. To handle synchro-
nisation I'm using spin locks, which are basically while loops."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Mon Mar 29, 2010 10:32 pm    Post subject: Reply with quote

iCodeBlog - Turbo Charging Your Apps With NSOperation

"Today, I will show you the simplest one: NSInvocationOperation. NSInvo-
cationOperation is a subclass of NSOperation which allows you to specify a
target and selector that will run as an operation."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Thu Apr 15, 2010 11:16 pm    Post subject: Reply with quote

discussions.apple.com - UIActivityIndicatorView in IBAction function

"I was wrong - you have to get back to the run loop for it to animate.

However you can do this pretty easily performing your long operation with
NSOperationQueue. Here's a simple example..."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Thu Apr 29, 2010 9:29 pm    Post subject: Reply with quote

MF - Offscreen bitmap drawing from background thread

"I have a scrollview containing about 100 smaller views, all the same size as
the screen. My problem is that when my app wants to show the scrollview it
takes about 5 seconds to create the contents of all those smaller views which
makes the app freeze for 5 seconds."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Tue May 11, 2010 9:02 pm    Post subject: Reply with quote

Jeff LaMarche - PSA: Respect the Main Thread

"Usually, I see these sleepForTimeInterval: calls in applications that do
some kind of asynchronous network communication. My guess is that the
developers who wrote these applications came from Java, .Net, or some
other language where network communication is commonly handled on a
non-main thread."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Mon May 24, 2010 11:31 pm    Post subject: Reply with quote

Jeff LaMarche - Downloading Images for a Table without Threads

"I've written a small iPhone app that downloads images from Deviant Art.
You just enter somebody's Deviant Art username into a text field and the
application will grab the the images in that person's gallery, download them
asynchronously, and display each one in the table once it's finished down-
loading."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Fri Jun 11, 2010 11:34 am    Post subject: Reply with quote

MF - Inter Thread Communication

"I want to be able to output the timer to a label back on my view controller
that is going to queue the NSOperation subclass.

I've found 'performSelectorOnMainThread:' method which should do what I
need. However, I'm a little fuzzy on how I can reference the main thread in
that function."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Fri Jul 23, 2010 3:12 pm    Post subject: Reply with quote

iphonedevsdk.com - NSThread-ing and SQLITE calls

"As it sends in "performselectorinMainThread" I'm looking for a way to make
sure that the method is independent of such calls, and thats why i've been
trying the performSelectorInBackgroundThread.. and NSThread detach..."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Sun Jul 25, 2010 11:06 pm    Post subject: Reply with quote

cimgf, Matt Long - NSOperation Example

"While looking around the Internet, I noticed that the only examples of using
NSOperation available were related to scientific applications. I wanted some-
thing that I could relate to a little better and since I’ve been working with QT-
Kit a lot lately, I figured it would be a good framework to build from."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Sun Jul 25, 2010 11:29 pm    Post subject: Reply with quote

so - Multi-Threading question in Objective-C 2.0

"I have my main application delegate which contains a method that returns
an object. This application delegate runs on the main thread.

I also have a NSOperation that gets run on a different thread. As well as
wanting to be able to call my app delegate method on my main thread
sometimes, I also need to call it from my NSOperation thread to get the
object that it returns."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Sun Jul 25, 2010 11:37 pm    Post subject: Reply with quote

cocoa samurai - A Guide to Threading on Leopard

"It's becoming abundantly clear that one big way you can increase appli-
cation performance is multithreading, this is because increasing processor
speeds are no longer a viable route for increasing application performance,
although it does help. Multithreading is splitting up your application into
multiple threads that execute concurrently with some threads having ac-
cess to the same data structures that your main thread has access to."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Mon Jul 26, 2010 11:51 pm    Post subject: Reply with quote

so - Queue of NSOperations and handling application exit

"How do I handle the situation where the application exits? As the operations
run in detached threads, how can I make the main thread wait until the cur-
rent operation is "safe" to quit?"
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Tue Jul 27, 2010 1:11 pm    Post subject: Reply with quote

adc - Mac OS X manual page for Atomic

"atomic add, increment, decrement, or, and, xor, compare and swap,
test and set, test and clear, spinlocks, and lockless queues"
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Wed Jul 28, 2010 1:35 am    Post subject: Reply with quote

so - NSOperation on the iPhone

"The ideal solution here would be to describe a use-case scenario for
NSOperation and how you would use it to solve your problem(s)."
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3136
Location: Europe

PostPosted: Mon Oct 04, 2010 7:34 pm    Post subject: Reply with quote

so - iOS App Architecture with NSOperations

"Does it create too much overhead? Does it even make sense? How you,
personally, implement concurrent operations?"
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3136
Location: Europe

PostPosted: Mon Oct 18, 2010 6:01 pm    Post subject: Reply with quote

MF - NSThread-ing and SQLITE calls

"In the operation it accesses the database and gets the results in chunks. I
found that 300 rows per chunk was a good size, YMMV. After each chunk has
been accumulated into an array that array is send to the main thread using
performMethodOnMainThread. The main thread then adds the results from
the array to its data model and calls reloadData."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Sat Feb 24, 2018 6:26 pm    Post subject: Reply with quote

nshipster - NSOperation

"Examples of tasks that lend themselves well to NSOperation include network
requests, image resizing, text processing, or any other repeatable, structured,
long-running task that produces associated state or data.

But simply wrapping computation into an object doesn't do much without a
little oversight. That's where NSOperationQueue comes in NSOperationQueue"
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Thu Jul 05, 2018 6:37 pm    Post subject: Reply with quote

so - UI API called on a background thread error

"UI API called on a background thread"

Code:
private class func getContext() -> NSManagedObjectContext {
    let appDelegate: AppDelegate
    if Thread.current.isMainThread {
        appDelegate = UIApplication.shared.delegate as! AppDelegate
    } else {
        appDelegate = DispatchQueue.main.sync {
            return UIApplication.shared.delegate as! AppDelegate
        }
    }
    return appDelegate.weatherPersistentContainer.viewContext
}
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Fri Jul 12, 2019 12:21 pm    Post subject: Reply with quote

medium - Managing background tasks with the new Task Scheduler in iOS 13

"Apple released another great framework this year, and this time it is the
BackgroundTasks framework. We can use it to schedule and control the
execution conditions of our background jobs. BackgroundTasks framework
allows us to plan and run background work according to required criteria like
when the battery is charging, connection availability, etc. BackgroundTasks
framework has various task types."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3524
Location: Zagreb

PostPosted: Thu Feb 20, 2020 6:38 pm    Post subject: Reply with quote

ioscoachfrank.com - Everything You Know About GCD Is a Lie

"Turns out that dispatching to the global queue is awful for performance.

Since the global queue lives right above the thread pool, it has to take liberties
with regards to how it handles quality of service and priorities. This means that
GCD (or more specifically, its scheduler) has less to work with when scheduling
your work."
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Igor Delovski Board Forum Index -> Mac Cocoa All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Delovski.hr
Powered by php-B.B. © 2001, 2005 php-B.B. Group