Easy way to multithread your apps

rharder

Do not read this sign.
I've made considerable improvements to the ThreadWorker class I brought up earlier. With just a single call, you can throw a job off onto another thread like this:
Code:
- (IBAction)buttonPressed:(id)sender
{
    [ThreadWorker workOn:self
     withSelector:@selector(longTask:)
     withObject:someArgument
     didEndSelector:@selector(allDone:)];
}
Control to the GUI will return immediately while your real work goes on. You can make calls to be executed on your calling thread just as easily from your working thread.

Anyhow, thought y'all might find it useful. It's Public Domain. You can find it at http://iharder.sourceforge.net/macosx/threadworker/

Enjoy.

-Rob
 

Attachments

  • threadworker-0.6.zip
    28 KB · Views: 9
You're welcome.

And to other Cocoa programmers out there: please use this or something like it. There's no need to perform, on the event-dispatching thread, any task that takes longer than a fraction of a second. Keep your apps responsive and put tasks on another thread. Please.

-Rob
 
You may have to make other parts of your program thread-safe, but, for instance, if you make calls to the "parent" thread through the supplied proxy, the thread-safeness is sort of taken care of already.

Now, if you are modifying some data object stored as a class's instance variable, and you are modifying it from both threads, then you may still need to lock it.

-Rob
 
Back
Top