Re: Cocoa class for queuing operations?
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