• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Threads & communication performance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threads & communication performance


  • Subject: Re: Threads & communication performance
  • From: Shaun Wexler <email@hidden>
  • Date: Mon, 8 Aug 2005 17:01:27 -0700

On Aug 8, 2005, at 3:16 PM, Laurent Michel wrote:

I have a behavior in my application that is somewhat disappointing and puzzling. In a nutshell, the application has two threads, one is a Cocoa thread and manages the UI, the other is compute-bound. The compute bound thread wishes to send 'updates' to the UI thread regularly (when events of interest occurs).

You are using a high-overhead approach which also tightly couples and effectively single-threads the process. You need to uncouple the GUI from the calculations, and minimize your cross-thread messaging. There are many more efficient ways to do this, but for brevity this should serve as an example:


#include <std_mail_disclaimer.h>

static UInt32 dataDirty __attribute__ ((aligned (4))) = 0;

- (void)calculationThread:(id)someObject
{
    while ([self hasWorkToDo])
    {
        [self performOneIterationOfWork];

if (CompareAndSwap(0, 1, &dataDirty)) {
NSData *data = [self copyDataForDisplay];
[self performSelectorOnMainThread:@selector(updateData:) withObject:data waitUntilDone:NO];
}
}
}


- (void)updateData:(NSData *)data
{
    [matrixController setMatrixWithCalculatedData:data];
    [matrix displayIfNeeded];
    CompareAndSwap(1, 0, &dataDirty);
    [data release];
}

If you use a custom matrix, you can add another atomic flag to - drawRect: and nearly eliminate all subsequent cross-thread perform messages, and Tiger will nicely limit drawing rate to max refresh for you.

HTH~
--
Shaun Wexler
MacFOH
http://www.macfoh.com

Efficiency is intelligent laziness.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Threads & communication performance
      • From: Laurent Michel <email@hidden>
References: 
 >Threads & communication performance (From: Laurent Michel <email@hidden>)

  • Prev by Date: Re: Question about Threading
  • Next by Date: Dashboard widget plugin with embedded framework
  • Previous by thread: Threads & communication performance
  • Next by thread: Re: Threads & communication performance
  • Index(es):
    • Date
    • Thread