• 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: Cocoa class for queuing operations?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa class for queuing operations?


  • Subject: Re: Cocoa class for queuing operations?
  • From: Shaun Wexler <email@hidden>
  • Date: Fri, 15 Jul 2005 08:24:50 -0700

On Jul 15, 2005, at 7:38 AM, Sherm Pendley wrote:

Couldn't you simply add a Category to NSMutableArray, and use @synchronized blocks within your methods to coordinate access?

@implementation NSMutableArray (SPThreadsafeQueuing)

-(void)threadsafePush:(id)obj {
    @synchronized(self) {
        [self addObject:obj];
    }
}

-(id)threadsafeShift {
    @synchronized(self) {
        id obj = [self objectAtIndex:0];
        [self removeObjectAtIndex:0];
        return obj;
    }
}

@end

You forgot to retain...

-(id)threadsafeShift {
    @synchronized(self) {
        id obj = [[self objectAtIndex:0] retain];
        [self removeObjectAtIndex:0];
        return [obj autorelease];
    }
}
--
Shaun Wexler
MacFOH
http://www.macfoh.com


_______________________________________________ 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
References: 
 >Cocoa class for queuing operations? (From: Jonathan del Strother <email@hidden>)
 >Re: Cocoa class for queuing operations? (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Preserving the authority to run a command line tool as root
  • Next by Date: Font control in TextView, TextStorage?
  • Previous by thread: Re: Cocoa class for queuing operations?
  • Next by thread: Attachable and observable patterns
  • Index(es):
    • Date
    • Thread